Skip to content

Fix exception handling in tunnel connections to prevent zombie connections#1071

Open
armorbreak001 wants to merge 1 commit intoencode:masterfrom
armorbreak001:fix/tunnel-exception-cleanup
Open

Fix exception handling in tunnel connections to prevent zombie connections#1071
armorbreak001 wants to merge 1 commit intoencode:masterfrom
armorbreak001:fix/tunnel-exception-cleanup

Conversation

@armorbreak001
Copy link
Copy Markdown

Summary

When an exception (e.g. TLS handshake failure) occurs during CONNECT tunnel setup in TunnelHTTPConnection/AsyncTunnelHTTPConnection, the underlying proxy connection was not being closed. This left zombie connections in the pool that could never be reused, eventually leading to pool starvation under error conditions.

The fix wraps the tunnel initialization block (CONNECT request → TLS upgrade → HTTP connection creation) in a try/except that ensures the proxy connection is properly cleaned up if setup fails before _connected is set to True.

Applies to both sync (httpcore/_sync/http_proxy.py) and async (httpcore/_async/http_proxy.py) implementations.

Fixes #1023

…tions

When a TLS handshake or other error occurs during CONNECT tunnel
setup, the underlying proxy connection was not being closed, leaving
it as a zombie that could never be reused. Wrap the tunnel
initialization in try/except to ensure proper cleanup on failure.
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.

Exceptions not handled properly in the proxy's AsyncTunnelHTTPConnection leading to the leaks and pool starvation

1 participant