Skip to content

Close sockets created before a failed bind - #394

Open
gyanu2507 wants to merge 1 commit into
pgjones:mainfrom
gyanu2507:fix/392-close-sockets-on-bind-failure
Open

gyanu2507 wants to merge 1 commit into
pgjones:mainfrom
gyanu2507:fix/392-close-sockets-on-bind-failure

Conversation

@gyanu2507

@gyanu2507 gyanu2507 commented Nov 3, 2026 •

Copy link
Copy Markdown

When _create_sockets hits a bind failure (for example EADDRINUSE), the socket that failed and any earlier successful binds were left open until GC, which shows up as ResourceWarning: unclosed <socket.socket ...>.

This closes the current socket on failure, closes earlier binds if the loop aborts, and uses detach() for fd:// sockets so the caller's file descriptor is not closed.

Fixes #392

When bind() raises, close the current socket and any earlier successful
binds so ResourceWarning does not fire from leftover fds. Detach fd://
sockets on failure so the caller's descriptor stays open.

Fixes pgjones#392

This branch has not been deployed

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

Config.create_sockets() leaves the socket unclosed when bind() fails

1 participant