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

Ensure HTTP::Client closes response when breaking out of block #12749

Conversation

straight-shoota
Copy link
Member

The request methods of HTTP::Client have a yielding overload which passes the response to the block, and cleans up after the block returns (mainly closing the body IO).
This cleanup logic is skipped when the block does not come back to that scope in case execution breaks out via raise or return.

This patch puts the cleanup logic into an ensure block to make sure it executes even when breaking out of the block.

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:networking labels Nov 17, 2022
Copy link
Member

@sdogruyol sdogruyol left a comment

Choose a reason for hiding this comment

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

Thank you @straight-shoota 🙏

@straight-shoota straight-shoota added this to the 1.7.0 milestone Nov 17, 2022
@straight-shoota straight-shoota merged commit dbed0d8 into crystal-lang:master Nov 19, 2022
@straight-shoota straight-shoota deleted the fix/http-client-ensure-handle_response branch November 19, 2022 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:networking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants