Repository navigation
fix(rate-limit): patch Bottleneck doExpire capacity leak - #9328
Merged
diegosouzapw merged 1 commit intoAug 11, 2026
Merged
diegosouzapw merged 1 commit into
diegosouzapw merged 1 commit into
Conversation
HouMinXi
force-pushed
the
fix/bottleneck-doexpire-patch-v2
branch
4 times, most recently
from
August 10, 2026 12:17
21717fa to
6c83d1c
Compare
diegosouzapw
force-pushed
the
fix/bottleneck-doexpire-patch-v2
branch
2 times, most recently
from
August 11, 2026 13:08
3edf0aa to
0803cb1
Compare
diegosouzapw
force-pushed
the
fix/bottleneck-doexpire-patch-v2
branch
from
August 11, 2026 13:13
0803cb1 to
2badd2d
Compare
diegosouzapw
merged commit Aug 11, 2026
fb83f43
into
diegosouzapw:release/v3.8.50
2 of 5 checks passed
muhamadgalihsaputra
pushed a commit
to niyatna/NiyatnaRoute
that referenced
this pull request
Sep 27, 2026
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.
Re-cut of #9151 onto the live
release/v3.8.50tip. The original branch shareda merge-base 20 commits behind and carried a
file-size-baseline.jsoncommitthat re-encoded every non-ASCII character in the file as
\uXXXX, so the diffread as +432/-184 with the whole baseline rewritten. Same fix, no rewrite:
4 files, +248/-0.
Problem
Bottleneck v2.19.5's
doExpire(Job.js:162) has a typo that compares the job IDto the string
"RUNNING"instead of checking the job's actual status. When ajob's execution time exceeds the
expirationtimeout,doExpirefires but failsto advance the job from RUNNING to EXECUTING. The resulting exception is
swallowed by
setTimeout, leaving the job permanently stuck in RUNNING state andBottleneck's internal
_runningcounter permanently incremented -- a capacityleak that eventually causes "all accounts inactive" even with available
reservoir.
The bug is unfixed upstream (v2.19.5 is the latest release; master still has it).
Fix
Monkey-patch
Bottleneck.prototype._runto correctjob.doExpirebeforethe expiration timeout fires. The patch uses
job.id(notjob.options.id)for status lookup, includes a
_doExpirePatchedguard against recursivewrapping, and adds optional chaining on
states.next.Diagnostic fallback in
withRateLimit: when a queue timeout fires and thelimiter shows
running > 0, executing = 0, reservoir > 0(the leak pattern)with no recent dispatch, evict the limiter and retry.
Files changed
open-sse/services/bottleneckPatch.tsopen-sse/services/rateLimitManager.tstests/unit/bottleneck-doexpire-patch.test.tsconfig/quality/file-size-baseline.jsonTesting
node --import tsx/esm --test tests/unit/bottleneck-doexpire-patch.test.ts-- 5/5 pass.
npm run typecheck:coreclean.npm run check:file-sizeandnpx eslinteach report one violation on thisbranch, both reproduced on an untouched
release/v3.8.50checkout(
open-sse/executors/base.ts1623 > 1578, and thetoNumberlocal definitionin
rateLimitManager.ts), so neither is introduced here and neither is fixedhere.