Repository navigation
Fix race condition in concurrent subtitle conversion - #17342
Merged
Merged
Conversation
SubtitleEncoder.ConvertSubtitles parsed subtitles with libse's static Subtitle.Parse, which iterates a statically cached list of shared SubtitleFormat instances. Format parsers keep mutable per-parse state on the instance, so concurrent subtitle requests corrupted each other's output (cues mixed across streams and languages, truncated files) or failed with NullReferenceException when format detection broke down and Subtitle.Parse returned null. Parse through the injected ISubtitleParser instead. SubtitleEditParser instantiates a fresh format parser per call, so requests no longer share state. Its Parse method now returns the libse Subtitle directly (the SubtitleTrackInfo flattening was unused since the SubtitleEdit writer rework) so the writers keep full fidelity such as ASS styling.
LTe
marked this pull request as ready for review
July 15, 2026 12:57
|
Shadowghost
approved these changes
Jul 15, 2026
Contributor
Jellyfin API (v 12.0.0)ResultNo differences. Specifications are equivalent |
crobibero
approved these changes
Jul 20, 2026
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.
Changes
SubtitleEncoder.ConvertSubtitlesparsed subtitles via libse's staticSubtitle.Parse, which uses a statically cached list of sharedSubtitleFormatinstances whose per-parse state is mutable — concurrent subtitle requests corrupted each other's output (cues mixed across streams/languages, truncated responses) or failed with aNullReferenceException(HTTP 500). This PR routes the conversion through the injectedISubtitleParser(SubtitleEditParser), which creates a fresh format parser per call.ISubtitleParser.Parsenow returns the libseSubtitledirectly — its previousSubtitleTrackInforeturn value had no callers since the SubtitleEdit writer rework (#16805), and returning the full document keeps writer fidelity (e.g. ASS styling). Adds tests asserting that concurrent conversions match a sequential baseline (fails on master, deterministic) and that sequential conversion is deterministic.Code assistance
Investigated and implemented with LLM assistance (Claude Code): root cause analysis of the race, the fix, and the accompanying tests. All changes were verified by building and running the test suite, including reproducing the corruption on master and confirming it disappears with the fix.
Issues
#17341