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

Add documentation to clarify if ResponseBody.close() is necessary #3400

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

tejas-n
Copy link

@tejas-n tejas-n commented May 24, 2020

Closes #2950, closes #2929

/**
* The deserialized response body of a {@linkplain #isSuccessful() successful} response.
*
* <p>If the body is of type {@link ResponseBody}, calling {@link ResponseBody#close close} is
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is helpful because it splits the type system.

By following this doc you need to differentiate between responses that are created from streaming endpoints and responses that are not. If you write general purpose code to accept a Response, you need to clarify whether it's a streaming one. Also if you add @Streaming you create a resource leak.

It's simpler and more resilient to document that this must be closed under all circumstances.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the reply. Yeah, that makes sense. So you are suggesting "If the body is of type ResponseBody, close() should always be called to avoid leaking resources"? Am I correct?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swankjesse I've updated the PR, can you let me know if that looks correct, please?

Comment on lines +153 to +154
* <p>If the body is of type {@link ResponseBody}, {@link ResponseBody#close()} must always be
* called to avoid leaking resources
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only true of @Streaming endpoints. I think this doc needs to live only on the @Streaming annotation and not here.

The one down below is still useful, however.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that makes sense. I'll try to update it tonight.

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

Successfully merging this pull request may close these issues.

Question: Do I need to close ResponseBody? Retrofit 2 Close ErrorResponse Body
3 participants