Skip to content

make the server's shutdown flag atomic - #1278

Merged
gittiver merged 1 commit into
CrowCpp:masterfrom
rowebb:fix-atomic-shutdown-flag
Oct 15, 2026
Merged

gittiver merged 1 commit into
CrowCpp:masterfrom
rowebb:fix-atomic-shutdown-flag

Conversation

@rowebb

@rowebb rowebb commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Server::stop() writes shutting_down_ on the thread that calls app.stop(). The io thread reads it in do_accept(), which the accept handler calls again after every accepted connection, and in that handler's error path. As a plain bool, nothing orders those accesses, so stopping an app from another thread (the usual way to stop one started with run_async()) is a data race that ThreadSanitizer reports. This makes the flag std::atomic<bool>. <atomic> is already included, and the write and both reads are unchanged.

Fixes #1277

Verification:

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.

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
gittiver merged commit 1309e0e into CrowCpp:master Oct 15, 2026
20 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.

data race on Server::shutting_down_ between stop() and the accept loop

2 participants