Shorten TMDB request timeout and retries; make env-tunable#451
Open
funkypenguin wants to merge 1 commit intocedya77:devfrom
Open
Shorten TMDB request timeout and retries; make env-tunable#451funkypenguin wants to merge 1 commit intocedya77:devfrom
funkypenguin wants to merge 1 commit intocedya77:devfrom
Conversation
makeTmdbRequest() retried up to 3 times with a 15-second AbortSignal timeout per attempt, meaning a single failing TMDB call could hold its response buffers and promise chain for 45 seconds before giving up. Under upstream brownouts (observed recently on a busy public instance) this stacks up across the dozens of concurrent TMDB calls that a single manifest/search/meta request can trigger, and the in-flight state piles up in the Node heap until it OOMs — raising --max-old-space-size to 8GB just delayed the failure by a few minutes because the actual problem was in-flight request volume, not retained data. New defaults: 5s × 2 attempts = 10s worst case (9x less held time). Env vars: TMDB_REQUEST_TIMEOUT_MS (default 5000) TMDB_MAX_RETRIES (default 2) Operators running into TMDB rate limits or flaky upstreams can tune these without rebuilding; self-hosted instances with spare TMDB quota can bump them back up. The existing backoff-on-429 logic is preserved and still honours the Retry-After header. Only affects TMDB. Similar treatment is warranted for TVmaze, Trakt, AniList, MAL, MDBList, Letterboxd, and IMDb Ratings — leaving those for follow-up PRs to keep this change focused and easy to review.
Contributor
PR Guard
Maintainers may still close PRs that do not match project direction or review capacity. |
This was referenced Apr 23, 2026
f1cf7c6 to
68d40bf
Compare
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.
Summary
Cut TMDB per-request timeout from 15s → 5s and max attempts from 3 → 2, both env-tunable. Worst-case held time per request drops from 45s to 10s.
Motivation
Under upstream TMDB brownouts (observed on a busy public instance), every concurrent TMDB call was holding its response buffer + promise chain for up to 45 seconds waiting on retries. A single manifest load fans out to dozens of TMDB calls; concurrent user traffic multiplies that. During a brief TMDB slowdown, the in-flight state stacked up faster than GC could reclaim it, taking the process to OOM even with
--max-old-space-size=8192.Example from the recent incident:
The process wasn't leaking memory — it was holding 8 GB of concurrent pending-TMDB-request state. Raising the heap limit doesn't help; shedding load faster does.
Change
Two one-line swaps in
makeTmdbRequest:New env vars
TMDB_REQUEST_TIMEOUT_MS5000TMDB_MAX_RETRIES2Self-hosters with private TMDB keys and spare quota can raise these back to prior values if they prefer aggressive retrying. Operators hitting rate limits or upstream flakiness can tune down further.
What's preserved
Retry-Afterheader — untouchedscrapedImdbIdCacheclear — untouchedFollow-ups (not in this PR)
Similar timeout/retry tuning is warranted for: TVmaze (75s worst case), Trakt (90s), AniList (90s), MAL/Jikan (45s), MDBList (50s), Letterboxd (90s), IMDb Ratings (120s), TVDB (24s). Keeping this PR focused on TMDB since that's the one in the incident log and the most frequently hit provider.
Test plan
node --checkon modified filedevRetry-Afterhandling still works for 429 responses (existing test path)🤖 Generated with Claude Code