Skip to content

Conversation

@benoitc
Copy link
Owner

@benoitc benoitc commented Jan 20, 2026

Summary

  • Fix connection leak when manually calling hackney:body/1 or stream_body/1
  • body/1,2 now releases connection to pool after successful read
  • stream_body/1 releases connection when returning done
  • Added hackney_pool_integration_tests verifying pool release behavior

Previously, only requests using the with_body option would properly release connections. Manual body reading would leave connections in the pool's in_use count but not return them for reuse.

@benoitc benoitc force-pushed the fix/pool-connection-release branch 2 times, most recently from 2da0562 to 1e869e6 Compare January 20, 2026 19:13
Connections are now automatically released to the pool when body reading
completes, rather than requiring explicit release calls. This is handled
in the connection process itself (hackney_conn) when transitioning from
receiving state to connected state.

Changes:
- hackney_conn: Add auto_release_to_pool in connected(enter, receiving, ...)
- hackney_conn: Add should_auto_release/1 and auto_release_to_pool/1 helpers
- hackney.erl: Remove safe_release_to_pool (no longer needed)
- hackney.erl: For HEAD requests, call body() to trigger auto-release
- Test: Add hackney_pool_integration_tests for HTTP/1.1 pool release
- Test: Add hackney_pool_h2_tests for HTTP/2 pool behavior

HTTP/2 and HTTP/3 connections use multiplexing and are handled differently:
- They stay registered in the pool until the connection closes
- Pool monitors them and cleans up on DOWN message
- Multiple callers share the same connection
@benoitc benoitc force-pushed the fix/pool-connection-release branch from 1e869e6 to f5211e3 Compare January 20, 2026 19:15
@benoitc benoitc merged commit f9e966b into master Jan 20, 2026
5 checks passed
@benoitc benoitc deleted the fix/pool-connection-release branch January 20, 2026 19:48
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.

2 participants