Skip to content

fix(server): make Stop() complete when the accept loop is blocked - #7

Open
andreion1ca wants to merge 1 commit into
AltServer-Websocket-Sharpfrom
fix/stop-hangs-when-accept-blocked
Open

fix(server): make Stop() complete when the accept loop is blocked#7
andreion1ca wants to merge 1 commit into
AltServer-Websocket-Sharpfrom
fix/stop-hangs-when-accept-blocked

Conversation

@andreion1ca

Copy link
Copy Markdown

TcpListener.Stop() blocks indefinitely on Unix when the accept thread is parked in a blocking AcceptTcpClient(). Because Stop() never returned, the server stayed in ShuttingDown forever and a later Start() silently no-opped (its guard returns early in that state), leaving the server permanently unable to accept connections.

  • Poll the listening socket (250ms) before accepting, so the accept loop notices a shutdown and exits on its own instead of blocking in Accept.
  • Join the receive thread before disposing the listener in stopReceiving(), so no thread is parked in Accept when the socket is closed.
  • Set SendTimeout on accepted sockets so a write to a peer that has gone unreachable (including the server-initiated close handshake) cannot block forever.

This makes Stop()/Start() usable at runtime, which AltServer needs in order to stop serving while a subscription cannot be verified and resume once it can be verified again.

TcpListener.Stop() blocks indefinitely on Unix when the accept thread is
parked in a blocking AcceptTcpClient(). Because Stop() never returned, the
server stayed in ShuttingDown forever and a later Start() silently no-opped
(its guard returns early in that state), leaving the server permanently
unable to accept connections.

- Poll the listening socket (250ms) before accepting, so the accept loop
  notices a shutdown and exits on its own instead of blocking in Accept.
- Join the receive thread before disposing the listener in stopReceiving(),
  so no thread is parked in Accept when the socket is closed.
- Set SendTimeout on accepted sockets so a write to a peer that has gone
  unreachable (including the server-initiated close handshake) cannot block
  forever.

This makes Stop()/Start() usable at runtime, which AltServer needs in order
to stop serving while a subscription cannot be verified and resume once it
can be verified again.
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.

1 participant