#162: ThreadChannel worker parked on recv() no longer hangs shutdown#167
Merged
Conversation
…l lock) The previous commit used a process-wide registry that the main thread iterated at quiesce to close every channel — one thread reaching into all threads' channels, behind a global mutex. Replace it with a per-thread registry in ASYNC_G: a channel created on a thread is registered there (holding a ref), and each thread closes the channels it created at its own engine_shutdown (before REACTOR_SHUTDOWN waits for child threads). No cross-thread access, no lock; the registry ref keeps a channel alive until its owner closes it. Re-proved: orphan_recv chaos sweep 150/150 (5 worker counts x random:1..30) on ASAN+async-fuzz, no hang/leak/UAF. Claude-Session: https://claude.ai/code/session_01NMdPEuD85qzTjv2N4ihTQU
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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 worker spawned via
Async\spawn_thread()and parked onThreadChannel::recv()kept the whole process alive when the owning side finished without
close().Fix (two parts):
while a coroutine actually
awaits the thread, so a non-awaited worker nolonger pins the parent, which reaches shutdown.
ThreadChannels it created and closes them at its ownengine_shutdown, so aworker parked on a channel whose owner finished wakes and exits. Thread-local,
no global lock; works for fan-out (any number of workers).
Tests:
thread_channel/042–044(recv / producer-coroutine / fan-out) + chaosfuzzy-tests/thread_channel/orphan_recv.featureproven 150/150 underrandom scheduler + ASAN (no hang/leak/UAF). Full thread/channel/coroutine/scope
suites green.