Repository navigation
make the server's shutdown flag atomic - #1278
Merged
Merged
Conversation
Server::stop() writes shutting_down_ on the thread that calls app.stop(), while the io thread reads it in do_accept() and its accept handler. As a plain bool nothing orders those accesses, which ThreadSanitizer reports as a data race whenever an app is stopped from another thread. Fixes CrowCpp#1277 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
gittiver
approved these changes
Oct 15, 2026
gittiver
approved these changes
Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Server::stop()writesshutting_down_on the thread that callsapp.stop(). The io thread reads it indo_accept(), which the accept handler calls again after every accepted connection, and in that handler's error path. As a plainbool, nothing orders those accesses, so stopping an app from another thread (the usual way to stop one started withrun_async()) is a data race that ThreadSanitizer reports. This makes the flagstd::atomic<bool>.<atomic>is already included, and the write and both reads are unchanged.Fixes #1277
Verification:
run_async(), make one request, stop from the main thread, repeated) was built with-fsanitize=thread. Over 10 runs of 50 cycles, master reports the race in 9 runs; with this change all 10 exit 0 with no reports.crow_testandtemplate_testpass.No test added: the race only fails under ThreadSanitizer, and the CI sanitizer job runs ASan and UBSan, so a test here would pass either way. If you'd like a TSan job in CI, I can open that separately.
This change and its description were prepared with Claude Code.