Commit c023053
Fix race condition in drain_streams_concurrently ensure block
The ensure block was checking client_disconnected before waiting for
writing_task to complete. This caused a race where the flag might still
be false when checked, even though writing_task would set it to true
moments later.
Fixed by reordering the ensure block:
1. Close queue (unblocks writing_task if waiting on dequeue)
2. Wait for writing_task (ensures flag is set if disconnect occurred)
3. Check flag and stop barrier if needed
This ensures producers are properly stopped when clients disconnect,
preventing wasted CPU cycles.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>1 parent b0c86d0 commit c023053
1 file changed
+8
-4
lines changedLines changed: 8 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
| 96 | + | |
100 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
101 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
102 | 106 | | |
103 | 107 | | |
104 | 108 | | |
| |||
0 commit comments