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

Should connection.disconnect() be called normally? #702

Closed
wmulligan opened this issue Apr 17, 2014 · 5 comments
Closed

Should connection.disconnect() be called normally? #702

wmulligan opened this issue Apr 17, 2014 · 5 comments

Comments

@wmulligan
Copy link

I am looking at your latest 1.5.4 changes.

Should we be calling HttpUrlConnection.disconnect after every request? The documentation is a bit vague about this.

When we call disconnect(), what happens if we have not read the entire response body yet? Is it possible that we could lose part of the response if we call disconnect() direct after getInputStream()?

Thanks!

@swankjesse
Copy link
Member

@wmulligan don't call disconnect until you're done with the connection. You can call it when you're done with the connection; it doesn't harm connection pooling or anything unless the disconnect is abrupt.

@wmulligan
Copy link
Author

Just to confirm, when we call getInputStream() and receive the inputstream, has the entire response body been buffered/received? Or is the input stream a live stream from the server that will block when we read it?

@swankjesse
Copy link
Member

You shouldn't call disconnect() until you're completely done with the connection. If you call disconnect early, your response body will be truncated.

@wmulligan
Copy link
Author

Alright thanks for the reply. One more question, what happens if we don't call disconnect()? Will the connection still be recycled without calling disconnect?

Why I am asking these questions is b/c we make network calls on one thread, and do parsing on another thread, so I am trying to figure out how to pass the inputStream to the parser, while not killing the connection. If we don't need to call disconnect, then that would solve the issue.

@swankjesse
Copy link
Member

You don't need to call disconnect. You do need to close the input stream containing the response body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants