Repository navigation
SyncBackend: failed socket setup retains open descriptors through exception tracebacks #1125
Unanswered
adenzhou1350
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
On current master (
10a658221deb38a4c5b16db55ab554b0bf731707), I reproduced delayed socket cleanup using real Linux sockets and the public synchronous connection pool.When a Unix-socket connect fails, the socket remains open in the exception traceback even after the pool context exits. Keeping 32
ConnectErrorinstances retains 32 descriptors, including aftergc.collect(). Releasing the exceptions and collecting returns to baseline. This is not a permanent/uncollectable leak; discarding errors also allows GC to recover the descriptors.The same ownership gap exists after successful TCP creation when
setsockopt()fails.SyncBackendhas no explicit cleanup between socket creation and transfer toSyncStream. This is separate from the TLS failure addressed by #443, and from async proxy/pool cancellation work.I have a small local fix that closes the created socket if subsequent setup raises, then re-raises without changing exception mapping. Six real-socket regression tests give 4 failures / 2 passes before, 6 passes after: missing Unix path, invalid Unix option, invalid Unix timeout, invalid TCP option, and successful Unix/TCP ownership transfer. A separate 12-cell real-FD probe has no retained descriptors after the fix, including the public pool case. Existing selected offline tests give 202 passes plus the same six existing XPASSes (not a full integration/platform matrix).
Would a focused cleanup PR covering these two backend methods be welcome? This backend file is not generated by
scripts/unasync.py; its generated targets are_async→_sync. Tested with Linux/Python 3.12.13. AI-assisted investigation and patch; the baseline/candidate native tests and the following public reproduction were executed independently.Current output:
With explicit failure cleanup both counts are zero. No FD exhaustion or production-incidence claim is intended.
All reactions