Skip to content

fix: Serialise Crow's Server::stop() on SIGTERM (#249) - #250

Merged
jrosskopf merged 1 commit into
mainfrom
fix/gh-249-concurrent-crow-stop
Nov 23, 2026
Merged

jrosskopf merged 1 commit into
mainfrom
fix/gh-249-concurrent-crow-stop

Conversation

@jrosskopf

@jrosskopf jrosskopf commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The 20 ms stop poll in APIServer::run called app.stop() without stop_mutex_, racing APIServer::stop()'s own call: two threads in Crow's non-thread-safe Server::stop(). Main's CI on the release commit 3d20f55 died with SIGSEGV this way (acceptor closed twice in the log).
  • Poll now uses try_lock on stop_mutex_; the startup-window guarantee (a stop before Crow publishes its server still takes effect) is unchanged.
  • Shutdown tests assert "Closing acceptor" appears exactly once (it did in 200/200 clean runs before; the CI crash log had it twice).

Test plan

  • test_graceful_shutdown, handler_offload, startup_failures, config_service: 44 passed
  • every test file using SIGTERM or the pause-before-bind seam: 283 passed
  • 120 standalone SIGTERM-with-task repros on 4 CPUs: all exit 0, one acceptor close each
  • full CI

The race is timing-dependent (0 in 200 local runs before the fix), so there is no deterministic red; the new assertion catches it whenever it fires.

Closes #249

🤖 Generated with Claude Code

https://claude.ai/code/session_018txuxF9jXyiKakpUoXrKBi


Start Proof
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…threads (#249)

- The stop poll in APIServer::run called app.stop() without stop_mutex_;
  APIServer::stop() sets stop_requested_ first and calls app.stop() under it,
  so both could run Crow's non-thread-safe Server::stop() at once
- Seen as SIGSEGV with an MCP task in flight on main's CI (3d20f55); the log
  closed the same acceptor twice
- try_lock in the poll: while stop() holds the lock it issues app.stop() itself,
  and the next tick retries, so a stop during startup still takes effect
- Shutdown tests assert the acceptor is closed exactly once
- Closes #249
@jrosskopf
jrosskopf merged commit a5b021c into main Nov 23, 2026
29 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.

SIGSEGV on SIGTERM: Crow's Server::stop() runs on two threads at once

1 participant