Skip to content

Release all resources when a Windows named pipe socket is closed - #100

Merged
eed3si9n merged 1 commit into
sbt:developfrom
lrytz:pr/win-socket-close
Oct 29, 2026
Merged

eed3si9n merged 1 commit into
sbt:developfrom
lrytz:pr/win-socket-close

Conversation

@lrytz

@lrytz lrytz commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Closing a Win32NamedPipeSocket didn't release everything it held:

  • On the client side, the pipe stayed open, so the server never noticed that the client was gone.
  • Every socket leaked two Windows event handles.
  • Every socket leaked a TCP socket. The base class java.net.Socket creates one when the read timeout is looked up, which every read does, and only Socket.close() releases it.

Now close() releases all of these, and calling it twice is harmless.

Behavior change: reading from a closed named pipe socket now throws SocketException("Socket is closed"), as java.net.Socket does. This comes from calling Socket.close(), which is needed to release the TCP socket.

Closing a Win32NamedPipeSocket didn't release everything it held:

- On the client side, the pipe stayed open, so the server never noticed
  that the client was gone.
- Every socket leaked two Windows event handles.
- Every socket leaked a TCP socket. The base class java.net.Socket
  creates one when the read timeout is looked up, which every read does,
  and only Socket.close() releases it.

Now close() releases all of these, and calling it twice is harmless.

Behavior change: reading from a closed named pipe socket now throws
SocketException("Socket is closed"), as java.net.Socket does. This comes
from calling Socket.close(), which is needed to release the TCP socket.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lrytz lrytz mentioned this pull request Oct 28, 2026

@eed3si9n eed3si9n left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@eed3si9n
eed3si9n merged commit b3b3eab into sbt:develop Oct 29, 2026
7 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