Skip to content

fix(debrid): limit torbox magnet checks to 2 per user at any given time#729

Closed
webstreamr wants to merge 1 commit intoViren070:mainfrom
webstreamr:torbox-magnet-check-limit
Closed

fix(debrid): limit torbox magnet checks to 2 per user at any given time#729
webstreamr wants to merge 1 commit intoViren070:mainfrom
webstreamr:torbox-magnet-check-limit

Conversation

@webstreamr
Copy link
Contributor

@webstreamr webstreamr commented Feb 13, 2026

this is a simple and stupid workaround to avoid hitting the 5/s limits with the current aiostreams design. it seems to work quite well on my local system and should still leave room for wrapped add-ons doing their own availability checks.

in case this gets merged - something similar will be needed for nzb checks too I suppose. I only have a single indexer and don't experience problems there though.

Summary by CodeRabbit

  • Dependencies

    • Added lru-cache dependency to manage cached controls and improve stability.
  • Performance Improvements

    • Improved magnet validation by introducing per-account concurrency limits, reducing request spikes and improving overall responsiveness and resource efficiency.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 13, 2026

Walkthrough

Adds per-token concurrency limiting for magnet checks in TorboxDebridService by introducing an LRU-backed cache of limiter functions and wiring checkMagnets to run via a per-token limiter.

Changes

Cohort / File(s) Summary
Repository root
package.json
Added lru-cache v11.2.6 to project dependencies.
Core package deps
packages/core/package.json
Added lru-cache dependency to the core package.
Concurrency control in Torbox
packages/core/src/debrid/torbox.ts
Added private readonly token field, a static checkMagnetsLimiters LRU cache, and changed checkMagnets to retrieve/create a per-token limiter (default capacity 2) and execute stremthru.checkMagnets through it.

Sequence Diagram(s)

sequenceDiagram
  rect rgba(200,200,255,0.5)
    participant Caller
    participant TorboxDebridService
    participant LRUCache
    participant StremThruInterface
  end

  Caller->>TorboxDebridService: checkMagnets(token, magnets)
  TorboxDebridService->>LRUCache: get or create limiter for token
  LRUCache-->>TorboxDebridService: limiter(function)
  TorboxDebridService->>limiter: run(() => stremthru.checkMagnets(magnets))
  limiter->>StremThruInterface: stremthru.checkMagnets(magnets)
  StremThruInterface-->>limiter: results
  limiter-->>TorboxDebridService: results
  TorboxDebridService-->>Caller: results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • Viren070

Poem

🐰 I hop from token to token with care,
A tiny LRU keeps limiters fair,
Two checks at a time, no frantic race,
Gentle throttles keep the pace,
Hooray — smooth magnets, tidy place!

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: implementing per-user concurrency limits (2 per token) on Torbox magnet checks to avoid rate limiting.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


Comment @coderabbitai help to get the list of available commands and usage tips.

@webstreamr webstreamr force-pushed the torbox-magnet-check-limit branch from c9604d2 to d0d9463 Compare February 13, 2026 21:10
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@package.json`:
- Around line 34-38: The core package is missing a direct dependency on
lru-cache even though packages/core/src/debrid/torbox.ts imports it; add
"lru-cache": "^11.2.6" to the dependencies object in packages/core/package.json
so the core package declares and installs this runtime dependency explicitly,
then run install to update the lockfiles.
🧹 Nitpick comments (1)
packages/core/src/debrid/torbox.ts (1)

154-161: Limiter is process‑local; consider cross‑instance coordination if you scale out.

This cache lives in‑process, so multiple server instances can still exceed 2 concurrent checks per token. If you run more than one Node process, consider a shared semaphore/queue (e.g., Redis) to enforce a global limit.

@webstreamr webstreamr force-pushed the torbox-magnet-check-limit branch from d0d9463 to c3dcb52 Compare February 13, 2026 21:11
@webstreamr webstreamr force-pushed the torbox-magnet-check-limit branch from c3dcb52 to d62a571 Compare February 13, 2026 21:13
return this.stremthru.checkMagnets(magnets, sid);
let limiter = TorboxDebridService.checkMagnetsLimiters.get(this.token);
if (!limiter) {
limiter = pLimit(2);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what a good number here is tbh and it's a bit hard to test right now because some systems have intermittent issues. maybe it should just be 1 🤷‍♂️

@webstreamr
Copy link
Contributor Author

TorBox raised limits to 300/s and ST switched to non-batched post requests. This dirty workaround is not needed for now.

@webstreamr webstreamr closed this Feb 14, 2026
@webstreamr webstreamr deleted the torbox-magnet-check-limit branch February 14, 2026 09:16
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.

1 participant