docs: document strand/thread_pool teardown precondition (#348)#354
Merged
mvandeberg merged 1 commit intoJul 2, 2026
Merged
Conversation
) A strand holds only a non-owning reference to its execution context. Posting or dispatching to a strand concurrently with, or after, that context's destruction is undefined behavior: it races service teardown (the cppalliance#348 null-deref of service_) and, past destroy(), a use-after-free on the freed service state and pool queue. This is a precondition violation, not a bug reachable by correct code: legitimate posts run on pool workers, and join()-before-shutdown() already ensures no worker is active when the service tears down. The safe pattern is to submit work through run/run_async (work-tracked, so join() waits for it) and to join() the context before destroying it. Document the requirement on strand (class + post()/dispatch()) and on the thread_pool destructor. No code change.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop-2 #354 +/- ##
==========================================
Coverage 98.29% 98.29%
==========================================
Files 77 79 +2
Lines 3984 3986 +2
==========================================
+ Hits 3916 3918 +2
Misses 68 68
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
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.
A strand holds only a non-owning reference to its execution context. Posting or dispatching to a strand concurrently with, or after, that context's destruction is undefined behavior: it races service teardown (the #348 null-deref of service_) and, past destroy(), a use-after-free on the freed service state and pool queue.
This is a precondition violation, not a bug reachable by correct code: legitimate posts run on pool workers, and join()-before-shutdown() already ensures no worker is active when the service tears down. The safe pattern is to submit work through run/run_async (work-tracked, so join() waits for it) and to join() the context before destroying it.
Document the requirement on strand (class + post()/dispatch()) and on the thread_pool destructor. No code change.