Skip to content

Conversation

@gbenson
Copy link
Contributor

@gbenson gbenson commented Sep 19, 2025

This fix implements RetryTransport.close() and .aclose() so the inner transports are freed when httpx.Client.close() or httpx.Client.aclose() is called. This avoids resource warnings about leaked SSL sockets when Python exits, e.g.:

ResourceWarning: unclosed <ssl.SSLSocket fd=11, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.1.6', 40038), raddr=('18.245.162.93', 443)>

Decisions:

  • I wasn't sure whether to close transport passed as arguments to RetryTransport.__init__, so I implemented the same behavior as httpx.Client.close(), which is to close all transports irrespective of where they came from.
  • RetryTransport.__init__ creates both sync and async transports if you don't pass one in, but RetryTransport.close() and .aclose() only close their own transport. I don't think this would cause problems since the one you close is likely the one you use, so the transport you don't close probably didn't ever open any sockets.

@will-ockmore
Copy link
Owner

Thanks for this @gbenson , your decisions are reasonable ones. I'll include in the next release.

@will-ockmore will-ockmore merged commit 5ec91d4 into will-ockmore:main Sep 19, 2025
5 checks passed
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