Skip to content

Destroy the server socket when binding it fails - #164

Merged
svenvc merged 1 commit into
svenvc:masterfrom
Gabriel-Darbord:destroy-socket-on-failed-bind
Oct 24, 2026
Merged

svenvc merged 1 commit into
svenvc:masterfrom
Gabriel-Darbord:destroy-socket-on-failed-bind

Conversation

@Gabriel-Darbord

Copy link
Copy Markdown
Contributor

Fixes #163.

Socket newTCP happens before the bind, so when listenOn: signals the socket is neither destroyed nor returned, and its three external semaphores stay registered until finalization. Wrapping the attempt in ifCurtailed: gives it ownership of the socket, the way ZnMultiThreadedServer>>#serveConnectionsOn: already does for an accepted one. The success path is unchanged.

No test here: the leak is only observable through Smalltalk externalObjects or Socket allInstances, and finalization reclaims it, so any test is timing-sensitive. Glad to add one in whatever form you prefer.

@svenvc

svenvc commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Yes, this is better for sure. Thank you !

@svenvc
svenvc merged commit 75796d1 into svenvc:master Oct 24, 2026
6 checks passed
@Gabriel-Darbord
Gabriel-Darbord deleted the destroy-socket-on-failed-bind branch October 24, 2026 11:46
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.

A failed server socket bind leaks the socket

2 participants