Repository navigation
Conversation
A 204 or 304 always ended with the socket dropped, so every such response cost a new TCP/TLS connection. Only drop it when the response declares a body anyway (Transfer-Encoding, or a non-zero Content-Length on a 204). Fixes benoitc#1048 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A 204 or 304 response no longer drops the socket. It is only dropped when the response declares a body anyway (
Transfer-Encoding, or a non-zeroContent-Lengthon a 204; a 304 may carry theContent-Lengthof the representation, which is not a body).Why
read_full_body/2andstream_body_chunk/1setsocket = undefinedfor every 204/304, so the connection was closed and never returned to the pool. A client polling an endpoint that answers 204 opened a new TCP/TLS connection per poll. Fixes #1048.How to test
rebar3 eunit --module=hackney_no_body_reuse_tests. The test counts connections accepted by a local server: 3 requests (204, 304 with content-length, 204) use 1 connection; it fails before the fix (3 connections). A second case checks a 204 that declares a body still closes the connection. The integration, h1 reuse and conn test modules also pass.AI disclosure: this change was written with Claude Code (AI-assisted) and reviewed/tested by me.
🤖 Generated with Claude Code