Ray's Knowledge Base
Unlock

A consumer that stops reading a bounded channel on error leaves its producers blocked forever

PitfallVerified 27 Sep 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

A pipeline with producers that send into a bounded channel and one consumer hangs forever at 0% CPU when the consumer fails, instead of reporting the error. In dftracer-utils, dftracer_view -o /dev/null on an indexed trace export hung forever when the output could not be opened, and the library could also abort.

Cause#

On the error, the consumer returned and stopped reading. The channel stayed full, so every producer waited in send for space that never came, and the task that waits for the producers never finished.

Fix#

On failure, the consumer must:

  1. Set a shared failed flag that the producers check, so they stop producing early.
  2. Keep reading (draining) the channel until all producers have closed it, and drop what it reads.
  3. Report the error after the drain.

Check every bounded-channel pipeline for this: find each place where a consumer can return early. Test it by forcing the consumer to fail (for example an output that cannot be opened) with a time limit on the test.

A scan that stops early (a limit, an error or a dropped consumer) has the same cause and can also leave its producer coroutine parked on the channel. The coroutine frames then leak, and Valgrind reports them: 232 leaks in the wildcards test, 1529 in view_duql and 56 in agg_extension. The fix has three parts:

  1. The cursor closes its channel.
  2. The run loop finishes leftover runnable work.
  3. The executor lets runnable work drain before it stops.

The same quiesce fix cut a Valgrind dask Python test from a 50 min timeout to 32 min (observed note, 2026-10-07, dftracer-utils).

Evidence#

  • dftracer-utils commit 754d239f fix(views): fail an indexed export that cannot open its output added the drain and the flag in view_export_index.cpp, with a regression test.
  • The test timed out with the old consumer (no drain, no flag) and passed with the fix. The same command then failed in about 1 second with an IO error.
  • The same risk remained in dftracer_pgzip: it can block if every compressor worker fails. It was not fixed in that change.

Also found by searching

  • dftracer_view -o /dev/null hangs forever at 0% CPU when the output file cannot be opened
  • my producer consumer pipeline deadlocks instead of reporting the error when the consumer fails
  • how do I shut down producers blocked on send to a bounded channel after the consumer errors out
  • bounded queue full, consumer returned early, producers stuck in send, need cancel flag and drain
  • Valgrind reports leaked coroutine frames after a scan stopped early at a limit
  • dftracer_view -o /dev/null hangs instead of printing error
  • how do I shut down producers cleanly when the consumer of a bounded channel fails
  • deadlock bounded queue consumer returned early on error, producers blocked, task waiting for producers never finishes