Skip to content

MOS-30: Fix graceful shutdown deadlock and timeout - #13

Merged
timoruohomaki merged 1 commit into
masterfrom
fix/MOS-30-graceful-shutdown
Nov 8, 2026
Merged

timoruohomaki merged 1 commit into
masterfrom
fix/MOS-30-graceful-shutdown

Conversation

@timoruohomaki

Copy link
Copy Markdown
Contributor

Shutdown never completed cleanly:

  • it held clientsMu while calling client.Close, which takes clientsMu again to unregister the client, so one connected client deadlocked it
  • Start counted itself in the wait group that Shutdown waits on, so shutdown always ran into ShutdownTimeout and reported a timeout
  • main returned right after cancelling, cutting client connections

Close clients after releasing the lock, track only the accept loop and client goroutines in the wait group, exit the accept loop on a closed listener, make Shutdown idempotent, and have main wait for the server to stop (bounded by ShutdownTimeout) before flushing Sentry.

Add regression tests for shutdown with 0, 1 and 3 clients and for a repeated Shutdown call.

Shutdown never completed cleanly:
- it held clientsMu while calling client.Close, which takes clientsMu
  again to unregister the client, so one connected client deadlocked it
- Start counted itself in the wait group that Shutdown waits on, so
  shutdown always ran into ShutdownTimeout and reported a timeout
- main returned right after cancelling, cutting client connections

Close clients after releasing the lock, track only the accept loop and
client goroutines in the wait group, exit the accept loop on a closed
listener, make Shutdown idempotent, and have main wait for the server
to stop (bounded by ShutdownTimeout) before flushing Sentry.

Add regression tests for shutdown with 0, 1 and 3 clients and for a
repeated Shutdown call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@timoruohomaki
timoruohomaki merged commit 89c8d15 into master Nov 8, 2026
3 checks passed
@timoruohomaki
timoruohomaki deleted the fix/MOS-30-graceful-shutdown branch November 8, 2026 11:54
@timoruohomaki
timoruohomaki restored the fix/MOS-30-graceful-shutdown branch November 8, 2026 14:30
@timoruohomaki
timoruohomaki deleted the fix/MOS-30-graceful-shutdown branch November 8, 2026 17:37
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