Skip to content

fix: keep the connection after a clean 204/304 response - #1051

Open
ARAYN7011 wants to merge 1 commit into
benoitc:masterfrom
ARAYN7011:fix/reuse-conn-after-204-304
Open

ARAYN7011 wants to merge 1 commit into
benoitc:masterfrom
ARAYN7011:fix/reuse-conn-after-204-304

Conversation

@ARAYN7011

Copy link
Copy Markdown
Contributor

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-zero Content-Length on a 204; a 304 may carry the Content-Length of the representation, which is not a body).

Why
read_full_body/2 and stream_body_chunk/1 set socket = undefined for 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

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>
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.

Connection is closed after every 204/304 response, even a clean one with no body (regression from 1.x)

1 participant