Fix orphaned queued reads when a freed worker slot is stolen concurrently (#404)

* Fix orphaned queued reads when a freed worker slot is stolen concurrently

ReadOrchestrator.runWorker's finally callback dequeues the oldest queued
read and asserts that createWorker succeeds ("we just freed up a worker").
That assumption races: the callback runs on a later microtask than the
worker's stop, and concurrent read() calls in that gap can LRU-evict the
freed worker and saturate every slot. The assert then throws as an
unhandled rejection after the read was removed from the queue but before
it was attached to any worker - its pending slices' promises never settle
and the awaiting reads hang forever.

Observed in production-like load (a 4-source composition player): 25
back-to-back occurrences saturating both workers, leaving clips
permanently undecodable.

Fix: create the worker first; only dequeue the read once a slot was
actually obtained. If every slot is busy, leave the read queued - each
running worker drains the queue from this same block when it stops, so
the read is picked up by whichever worker stops next.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* Update logic

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
Co-authored-by: Vanilagy <[email protected]>
This commit is contained in:
Tom Yang
2026-06-16 09:26:40 +00:00
committed by GitHub
co-authored by Claude Opus 4.8 Vanilagy
parent ad167c77e7
commit 08e3a85370
+1 -1
View File
@@ -2108,7 +2108,7 @@ class ReadOrchestrator {
}
})
.finally(() => {
if (worker.running) {
if (worker.running || this.workers.length >= this.options.maxWorkerCount) {
// Rare, but can happen with multiple concurrent reads. In this case, don't do anything.
return;
}