-
Notifications
You must be signed in to change notification settings - Fork 36
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
http4s client tries to re-run body stream, possibly uses disposed connection #391
Comments
We ran into a case, most likely caused by this issue, where when we try to decode a large (49,084 characters) response we get an exception: Function looks like this:
And we are getting a 404 back but we are not able to decode the response. @amarrella If you could look at it tomorrow, that would be great, it's blocking some of our work. |
The best thing would be to return a fs2.Stream in all the functions, but that's a pretty big breaking change.
but this would add the requirement for I think the only option we have for now is replacing the fetch call with this:
@fiadliel what do you think? |
OK, bad news @mchimirev. After talking with @fiadliel we came to the conclusion that client is broken in this case and the only way to fix it is a pretty big breaking change (the ones suggested above won't solve the issue). My suggestion for now is to unfortunately not use the client, do the client manually and use the apibuilder ModelsJson. @gheine @fiadliel any suggestion on how to move forward with this? |
So the problem is confined to non-unit error responses and their lazily parsing the response body. A quick fix could be to make the error type non-lazy, ie. deserialize when the error response case class is constructed, similar to what happens when non-error response types are deserialized. |
ie change from
|
Tested using For example, this was old code to handle 409:
And this is new code:
|
* Moved error models to client class and removed effect * Added errors object within the client to avoid namespace conflicts * Formatting * Fixed error scope in client * Parsing json body before returning. Solves #391 * Lifted body into F for backward compatibility and renamed decoded body to 'body' * Inlined exceptionclass and simplified pattern match
…#392) * Moved error models to client class and removed effect * Added errors object within the client to avoid namespace conflicts * Formatting * Fixed error scope in client * Parsing json body before returning. Solves apicollective#391 * Lifted body into F for backward compatibility and renamed decoded body to 'body' * Inlined exceptionclass and simplified pattern match
_executeRequest
is defined like this:and uses the
fetch
method of the http4s client:If we look at the scaladoc for
fetch
:This means you should not access the body after this point in the code.
However, when an expected error occurs, the response is given back, including a call which tries to parse JSON in a lazy val. This is fundamentally unsafe for two reasons:
fetch
block).The text was updated successfully, but these errors were encountered: