Skip to content

Conversation

alltilla
Copy link
Contributor

Changes

SubtitleFormat's LoadSubtitle() function is not thread-safe.

A SubtitleEditParser instance's Parse() function can be called from multiple threads at the same time.

SubtitleFormats are cached in the constructor of each SubtitleEditParser, and the same instances are used for each possibly parallel Parse() function call, which causes subtitle parse problems.

This patch modifies the code, so we only cache the extension -> SubtitleFormat type/class mapping and create a new SubtitleFormat instance in each Parse() call, so no SubtitleFormat instance is accessed from multiple threads.

Issues

Fixes #12113

Kudos for everyone investigating the issue there, most notably @RenV123 for PoC-ing the solution.

@RenV123
Copy link

RenV123 commented Jan 17, 2025

I've tested this using the reproduction steps (with media containing 2 external srt subtitle files) and using chromecast on a wide range of content (that had problems in the past) and so far I haven't found any issues with subtitles.
It all looks good to me!

@gnattu
Copy link
Member

gnattu commented Jan 17, 2025

Probably targeting 10.10 and backport to master would be better

@BarbUk
Copy link

BarbUk commented Jan 18, 2025

I confirm that it solves the issues with several media that had the problem before, mainly mkv with several sub tracks.

@alltilla alltilla changed the base branch from master to release-10.10.z January 18, 2025 20:13
@alltilla
Copy link
Contributor Author

@gnattu Changed the base branch to release-10.10.z.

`SubtitleFormat`'s `LoadSubtitle()` function is
not thread-safe.

A `SubtitleEditParser` instance's `Parse()`
function can be called from multiple threads at
the same time.

`SubtitleFormat`s are cached in the constructor
of each `SubtitleEditParser`, and the same
instances are used for each possibly parallel
`Parse()` function call, which causes subtitle
parse problems.

This patch modifies the code, so we only cache
the extension -> `SubtitleFormat` type/class
mapping and create a new `SubtitleFormat`
instance in each `Parse()` call, so no
`SubtitleFormat` instance is accessed from
multiple threads.

Fixes jellyfin#12113

Kudos for everyone investigating the issue there,
most notably @RenV123 for PoC-ing the solution.

Signed-off-by: Attila Szakacs <szakacs.attila96@gmail.com>
@alltilla alltilla force-pushed the fix-parallel-subtitleeditparse branch from 088fb64 to c693da9 Compare January 18, 2025 20:16
@Shadowghost Shadowghost added the stable backport Backport into the next stable release label Jan 18, 2025
@joshuaboniface joshuaboniface merged commit 0b2a59e into jellyfin:release-10.10.z Jan 25, 2025
18 of 19 checks passed
Bond-009 pushed a commit that referenced this pull request Feb 3, 2025
Fix parallel use of not thread-safe SubtitleFormat instance

Original-merge: 0b2a59e

Merged-by: joshuaboniface <joshua@boniface.me>

Backported-by: Bond_009 <bond.009@outlook.com>
@jellyfin-bot jellyfin-bot removed the stable backport Backport into the next stable release label Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Issue]: Broken subtitles: Multiple languages and timestamps mixing up on screen when using chromecast
7 participants