Skip to content

CLDSRV-980: Make stopRefillJob actually stop the refill job - #6260

Closed
anurag4DSB wants to merge 1 commit into
development/9.3from
bugfix/CLDSRV-980-refill-job-cannot-be-stopped
Closed

CLDSRV-980: Make stopRefillJob actually stop the refill job#6260
anurag4DSB wants to merge 1 commit into
development/9.3from
bugfix/CLDSRV-980-refill-job-cannot-be-stopped

Conversation

@anurag4DSB

Copy link
Copy Markdown
Contributor

Intent: why does this change exist?

stopRefillJob() did not stop the rate limit refill job. Found while investigating RD-2240; unrelated to that memory leak beyond sharing the module.

System impact: what's affected, including downstream?

lib/api/apiUtils/rateLimit/refillJob.js only. startRefillJob gains an optional options argument ({ skipUnref }), mirroring startCleanupJob; the single production caller in lib/server.js is unchanged and takes the new default. The refill timer is now unref()'d, so it no longer holds the event loop open — the HTTP servers keep the process alive, as they already did for the cleanup job.

Preserved behavior: what explicitly stays the same?

Refill cadence, cleanup cadence, and everything the job does per tick. Start, stop, repeated stop and restart-after-stop all behave as before.

Intended change: what's different after this PR?

A running flag gates the re-arm at the end of tick, so a tick that was mid-await when stop ran no longer replaces the timer stop just cleared. startRefillJob also refuses a second concurrent start instead of orphaning the first timer, and warns.

Production impact was limited before this, because cleanUp() ends in process.exit(0) and overrides a live handle. What it did mean is that the job kept hitting Redis and mutating token buckets through the shutdown window, and leaked a live timer into any test that started it.

Verification: how do we know this worked, or how would we know if it didn't?

Two regression tests, written first and confirmed failing against stock. The mid-tick one uses a refill slower than the tick interval so a tick is guaranteed to be in flight at stop; on stock it reports the job still running, and the double-start one measured 12 refills in 450ms where a single loop gives about 4 — roughly three overlapping loops.

Rate limit suite 183 passing, 0 failing. Lint clean apart from two pre-existing prefer-await-to-then warnings on untouched lines.

@bert-e

bert-e commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Hello anurag4dsb,

My role is to assist you with the merge of this
pull request. Please type @bert-e help to get information
on this process, or consult the user documentation.

Available options
name description privileged authored
/after_pull_request Wait for the given pull request id to be merged before continuing with the current one.
/bypass_author_approval Bypass the pull request author's approval
/bypass_build_status Bypass the build and test status
/bypass_commit_size Bypass the check on the size of the changeset TBA
/bypass_incompatible_branch Bypass the check on the source branch prefix
/bypass_jira_check Bypass the Jira issue check
/bypass_peer_approval Bypass the pull request peers' approval
/bypass_leader_approval Bypass the pull request leaders' approval
/approve Instruct Bert-E that the author has approved the pull request. ✍️
/create_pull_requests Allow the creation of integration pull requests.
/create_integration_branches Allow the creation of integration branches.
/no_octopus Prevent Wall-E from doing any octopus merge and use multiple consecutive merge instead
/unanimity Change review acceptance criteria from one reviewer at least to all reviewers
/wait Instruct Bert-E not to run until further notice.
Available commands
name description privileged
/help Print Bert-E's manual in the pull request.
/status Print Bert-E's current status in the pull request.
/clear Remove all comments from Bert-E from the history TBA
/retry Re-start a fresh build TBA
/build Re-start a fresh build TBA
/force_reset Delete integration branches & pull requests, and restart merge process from the beginning.
/reset Try to remove integration branches unless there are commits on them which do not appear on the source branch.

Status report is not available.

@bert-e

bert-e commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Incorrect fix version

The Fix Version/s in issue CLDSRV-980 contains:

  • None

Considering where you are trying to merge, I ignored possible hotfix versions and I expected to find:

  • 9.3.17

  • 9.4.2

Please check the Fix Version/s of CLDSRV-980, or the target
branch of this pull request.

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.19%. Comparing base (24fb6b3) to head (36120ee).
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

Files with missing lines Coverage Δ
lib/api/apiUtils/rateLimit/refillJob.js 92.30% <100.00%> (+2.83%) ⬆️
@@                 Coverage Diff                 @@
##           development/9.3    #6260      +/-   ##
===================================================
+ Coverage            85.17%   85.19%   +0.01%     
===================================================
  Files                  206      206              
  Lines                13424    13438      +14     
===================================================
+ Hits                 11434    11448      +14     
  Misses                1990     1990              
Flag Coverage Δ
file-ft-tests-null-compat 62.97% <81.25%> (-5.93%) ⬇️
kmip-ft-tests 28.41% <81.25%> (+0.05%) ⬆️
mongo-v0-ft-tests 69.56% <81.25%> (+<0.01%) ⬆️
mongo-v1-ft-tests 69.54% <81.25%> (-0.07%) ⬇️
multiple-backend 36.88% <81.25%> (+0.04%) ⬆️
s3c-ft-tests-v1 63.99% <6.25%> (-0.06%) ⬇️
sur-tests 36.02% <81.25%> (+0.04%) ⬆️
sur-tests-inflights 37.85% <81.25%> (+0.01%) ⬆️
unit 71.16% <100.00%> (+0.07%) ⬆️
utapi-v2-tests 34.67% <81.25%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bert-e

bert-e commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Request integration branches

Waiting for integration branch creation to be requested by the user.

To request integration branches, please comment on this pull request with the following command:

/create_integration_branches

Alternatively, the /approve and /create_pull_requests commands will automatically
create the integration branches.

tick is async and ended with an unconditional setTimeout, so a tick that
was awaiting when stopRefillJob() ran would resume and re-arm the timer
stop had just cleared. The job then carried on for the rest of the
process lifetime. Measured before the fix: 4 further refill passes in the
1.5s after stopRefillJob() returned.

refillJobRunning now gates the re-arm, and startRefillJob refuses a
second concurrent start rather than orphaning the first timer - stock
code left about three overlapping loops behind across a test run,
refilling at several times the intended rate.

The timer is also unref()'d, as the cleanup job's already is, so it no
longer holds the event loop open. Tests opt out via skipUnref, matching
startCleanupJob.
@anurag4DSB
anurag4DSB force-pushed the bugfix/CLDSRV-980-refill-job-cannot-be-stopped branch from d421859 to 36120ee Compare August 20, 2026 14:21
@anurag4DSB anurag4DSB closed this Aug 20, 2026
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.

2 participants