Defer FFmpeg resource cleanup when a worker misses the stop timeout - #100
Defer FFmpeg resource cleanup when a worker misses the stop timeout#100Blackspirits wants to merge 1 commit into
Conversation
Blackspirits
left a comment
There was a problem hiding this comment.
Independent adversarial re-check: Session.Dispose is now idempotent; resources are released synchronously only after every worker has stopped. If any worker misses the bounded join (or Dispose is called from a worker), cleanup is deferred to a background task that retains the Session, joins all workers to completion, then disposes the sink/events/AVFormatContext and only afterward releases the interrupt GCHandle. This removes the previous use-after-free window at the cost of bounded resource retention if native I/O refuses to stop. Full CI #34780310800 passed restore, build and the complete suite on the first run; UITests reported 5,151 passed, 9 skipped, 0 failed. Retry was not used. A separate stale-frame publication guard is being validated because deferred workers can still finish a present iteration after close. Keep draft; no merge performed.
Summary
Even with #99's FFmpeg interrupt callback,
Session.Disposestill had a dangerous fallback: each worker gets a bounded join, but after a timeout the code immediately disposes the audio sink, wait handles,AVFormatContext, and callback state anyway.If a protocol, driver, or native call ignores/delays the interrupt callback, a timed-out worker can therefore continue running against resources that have already been released.
This change, layered on #99:
Session.Disposeidempotent;GCHandle.The failure mode is deliberately changed from possible use-after-free to temporary resource retention if native I/O refuses to terminate.
Validation
1e442fe91711253ba3e843bdf2f1e5bc4730e4f6AI assistance: ChatGPT was used to adversarially review FFmpeg worker/resource lifetime after bounded thread joins.