Commit Graph
1 Commits
Author SHA1 Message Date
hi.jack2eeandGitHub 6c88763a5c Terminate sample iterators before throwing so late-decoded samples are closed (#484)
for await never calls return() on an iterator whose next() threw, so the
error branches in mediaSamplesInRange / mediaSamplesAtTimestamps left the
iteration un-terminated: the pump's decoder callback kept queueing decoded
samples that no consumer or cleanup path could ever close, orphaning them
until GC ("A VideoSample was garbage collected without first being closed").

Set terminated (and ended, where the pump gates on it) before throwing in
both the InputDisposedError and out-of-band error branches of both sample
generators - samples emitted after the throw are then closed on arrival by
the existing checks in the decoder callbacks.

Observed on iOS Safari when the hardware VideoDecoder dies mid-iteration
("Decoding task did not complete"): 3-14 samples orphaned per failing
iterator; with this change, at most the single sample already in flight
during the error microtask window.
2026-09-04 10:01:18 +02:00