Fence FFmpeg close cleanup by load generation - #142
Draft
Blackspirits wants to merge 1 commit into
Draft
Blackspirits wants to merge 1 commit into
Blackspirits wants to merge 1 commit into
Conversation
Blackspirits
commented
Sep 16, 2026
Blackspirits
left a comment
Owner
Author
There was a problem hiding this comment.
Final adversarial review on 6cfde218dfd95e43e7e12077178e95b6969a57c4 after CI SubtitleEdit#281: no blocker found. The close-generated load generation is captured before teardown wait; owner cleanup is rejected after a replacement load advances generation; accepted cleanup orders decoder/frame clear and frame-version increment under the current-frame lock; FrameReady is emitted only for accepted cleanup. No merge/promotion performed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Dependent owner-lifetime follow-up to #140 ("Reclaim FFmpeg sessions after late worker exit").
#139 fences late Session workers from publishing stale decoder/frame state, and #140 allows a timed-out Session to reclaim itself once its last worker exits. This audit found the inverse race in the owner's own CloseFile cleanup: an older CloseFile can finish after a newer load has already published state and erase that newer state.
Current upstream
SubtitleEdit/subtitleeditmain was rechecked atd6917286e355976da953d0ee22208b4bf9461699; no relevant drift or open upstream PR was found.Finding fixed
CloseFile()previously did:_loadGeneration;session.Dispose();_decoderNameand_currentFrame.#115/#140 deliberately allow Session teardown to wait on workers and, on timeout, retain resources safely. During that wait another LoadFile can run, create a newer generation and publish its own decoder badge/frame.
When the older CloseFile eventually resumes, its unconditional cleanup could then erase the new Session's owner-visible media state.
Fix
TryClearOwnerMediaStateForGeneration(generation);FrameReadyfires only for accepted/current cleanup.This mirrors #139's generation fence in the opposite direction: stale workers cannot publish forward, and stale closes cannot erase forward.
Regression coverage
A native-free test creates generation 1 media state and proves:
Scope / branch state
4edde2ba42d0e81ce3d1504818eb13a3e7af606f6cfde218dfd95e43e7e12077178e95b6969a57c4d6917286e355976da953d0ee22208b4bf9461699AI assistance: ChatGPT was used for adversarial concurrent CloseFile/LoadFile ordering review, owner-state generation fencing and focused frame/decoder regression design.
Final CI
Authoritative run: SubtitleEdit#281 on
6cfde218dfd95e43e7e12077178e95b6969a57c4Final adversarial review was performed on this exact HEAD after CI; no blocker found.