mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-04 18:09:12 +03:00
[PR #4223] [CLOSED] Make TvdbClientManager thread safe #9957
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/jellyfin/jellyfin/pull/4223
Author: @Spacetech
Created: 9/28/2020
Status: ❌ Closed
Base:
master← Head:tvdbclient_thread_safety📝 Commits (4)
49522a4Make TvdbClientManager thread safeb739475update based on suggestions9316336move WaitAsync outside the try statement00e291dMerge branch 'master' into tvdbclient_thread_safety📊 Changes
1 file changed (+96 additions, -50 deletions)
View changed files
📝
MediaBrowser.Providers/Plugins/TheTvdb/TvdbClientManager.cs(+96 -50)📄 Description
Along with #4222, another issue I ran into was when multiple
TvdbClientManagercalls ran concurrently.Here's some errors that will happen if you try that:
It's complaining about setting
AcceptedLanguageand callingAuthenticateAsync.A fix is to have individual clients per language, so
AcceptedLanguageis set once during the initial creation. Along with that, add a locking mechanism to prevent concurrent authentication requests.Changes
ConcurrentDictionaryofTvDbClients per language.GetTvDbClientto return a specific langaugesTvDbClientand make it async so the token methods can be await'dTryGetValueto useGetOrCreateAsync. Something to note is thatMemoryCache.GetOrCreateAsyncis thread safe but has odd behavior (ref 1, ref 2). So it might run the factory a few times for the same key at the start. This is kind of annoying but might not be a huge issue for this use case.UtcNowfor the tokenDateTimesince it's less scary than local times.Issues
None
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.