Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null check bug fixes and tweak accessibility of properties on TransportResponse #144

Merged
merged 6 commits into from
Nov 21, 2024

Conversation

stevejgordon
Copy link
Collaborator

DefaultResponseFactory was throwing if the response stream was null. This can occur when an exception is thrown when sending the request (e.g., HttpRequestException), for example, when the HttpClient cannot connect to the endpoint. Rather than throwing a null exception here, we still want to return a response with the original exception attached.

In StreamResponse, we must safety-check that any linked disposables are not null before attempting to dispose of them.

The final change in TransportResponse is a tweak for the ingest work. The BulkStreamingResponse was initially derived from the StreamResponse to share behaviour. However, this causes the Body property (stream) to be present on the derived type. As we are handling stream reading internally, this is unnecessary and could produce weird behaviour if the consumer tries to access the stream directly. Instead, BulkStreamingResponse derives directly from TransportResponse, overriding LeaveOpen and handling LinkedDisposables in its own Dispose method.

This means we could potentially seal StreamResponse again. However, it might still be helpful for consumers to derive responses from this for advanced scenarios, with the base class doing the right thing during disposal. I am open to thoughts on whether that's likely to happen. @flobernd, were you deriving from this in the client?

@flobernd flobernd added the bug Something isn't working label Nov 21, 2024
@flobernd
Copy link
Member

This means we could potentially seal StreamResponse again. However, it might still be helpful for consumers to derive responses from this for advanced scenarios, with the base class doing the right thing during disposal. I am open to thoughts on whether that's likely to happen. @flobernd, were you deriving from this in the client?

I'm using a dedicated ResponseBuilder for the EsqlQueryResponse which is currently the only response type that access the raw stream, so sealing StreamResponse again would not be a breaking change for me.

I think we should seal it. A custom ResponseBuilder is required anyways to correctly instantiate the derived type. We could introduce an abstract StreamResponseBase that takes Stream in its constructor and derive StreamResponse from that. The base class should implement IDisposable and is intended to derive from, whereas StreamResponse itself remains as a quick solution to get access to the raw stream.

@stevejgordon
Copy link
Collaborator Author

@flobernd, that makes sense. I'll amend this PR to include that change.

@stevejgordon stevejgordon merged commit 1bd2db0 into main Nov 21, 2024
5 checks passed
@stevejgordon stevejgordon deleted the tweaks-for-ingest branch November 21, 2024 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v0.5.5
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants