Repository navigation
fix(rate-limit): prevent endless queue with maxWait (#297) #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -59,13 +59,19 @@ const PERSIST_DEBOUNCE_MS = 60_000; // Debounce persistence to every 60s max | |||||||||||
| // Track initialization | ||||||||||||
| let initialized = false; | ||||||||||||
|
|
||||||||||||
| // Max time (ms) a job can wait in queue before failing with a timeout error. | ||||||||||||
| // Prevents infinite queuing when all providers are exhausted after a 429. | ||||||||||||
| // Configurable via RATE_LIMIT_MAX_WAIT_MS env var (default: 2 minutes). | ||||||||||||
| const MAX_WAIT_MS = parseInt(process.env.RATE_LIMIT_MAX_WAIT_MS || "120000", 10); | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current parsing of
Suggested change
|
||||||||||||
| const MAX_WAIT_MS = parseInt(process.env.RATE_LIMIT_MAX_WAIT_MS || "120000", 10); | |
| const RAW_MAX_WAIT_MS = toNumber(process.env.RATE_LIMIT_MAX_WAIT_MS, 120000); | |
| const MAX_WAIT_MS = Math.max(0, Math.floor(RAW_MAX_WAIT_MS)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CRITICAL: maxWait is not a valid Bottleneck option — Bottleneck v2.19.5 does not support this property. It will be silently ignored, and jobs will still queue indefinitely. The intended fail-fast behavior will not work.
Consider using maxQueue to limit queue size (by count), or implementing a custom timeout wrapper using Promise.race() with a timeout promise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CRITICAL: maxWait is not a valid Bottleneck option — this will be silently ignored. See comment on line 74.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CRITICAL: maxWait is not a valid Bottleneck option — this will be silently ignored. See comment on line 74.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARNING: Missing validation for invalid or negative values —
parseIntreturnsNaNfor non-numeric strings (e.g.,RATE_LIMIT_MAX_WAIT_MS=abc), and negative values would be invalid timeouts. Consider adding validation: