Skip to content

#162: ThreadChannel worker parked on recv() no longer hangs shutdown#167

Merged
EdmondDantes merged 1 commit into
mainfrom
162-threadchannel-worker-parked-on-recv-hangs-process-shutdown-when-the-sender-finishes-without-close
Jun 25, 2026
Merged

#162: ThreadChannel worker parked on recv() no longer hangs shutdown#167
EdmondDantes merged 1 commit into
mainfrom
162-threadchannel-worker-parked-on-recv-hangs-process-shutdown-when-the-sender-finishes-without-close

Conversation

@EdmondDantes

@EdmondDantes EdmondDantes commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

A worker spawned via Async\spawn_thread() and parked on ThreadChannel::recv()
kept the whole process alive when the owning side finished without close().

Fix (two parts):

  1. Transparent thread completion event — it only keeps the parent loop alive
    while a coroutine actually awaits the thread, so a non-awaited worker no
    longer pins the parent, which reaches shutdown.
  2. Per-thread channel registry — each thread tracks (with a ref) the
    ThreadChannels it created and closes them at its own engine_shutdown, so a
    worker 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/042044 (recv / producer-coroutine / fan-out) + chaos
fuzzy-tests/thread_channel/orphan_recv.feature proven 150/150 under
random scheduler + ASAN (no hang/leak/UAF). Full thread/channel/coroutine/scope
suites green.

…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

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@EdmondDantes EdmondDantes merged commit 76e1e9d into main Jun 25, 2026
9 checks passed
@EdmondDantes EdmondDantes deleted the 162-threadchannel-worker-parked-on-recv-hangs-process-shutdown-when-the-sender-finishes-without-close branch June 25, 2026 19:43
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.

1 participant