Repository navigation
fix(worker): no request waits on the Access key fetch of another request - #73
Merged
Merged
Conversation
Collaborator
Author
|
🤖 |
…fetch time limit, newest fetch only
wojciechszyjka
commented
Nov 30, 2026
wojciechszyjka
left a comment
Collaborator
Author
There was a problem hiding this comment.
🤖 om-auto-review-pr: review of 8b1776f. Verdict: approve (posted as a comment, since an author cannot approve their own PR). The PR is left for the coordinating session to merge.
An independent reviewer found no security defect: the isolate keeps only the parsed keys and three numbers, and no key outside the latest applied set is accepted. Its findings are fixed in 8b1776f.
Majors (fixed):
- After a failure, the retry was 1 s after the fetch started. It is now
JWKS_RETRY_MSafter the failure settled, doubled for each failure in a row up to the 10 s window. - A fetch slower than the wait could refuse requests that the old code let through. The default fetch now has the same 3 s time limit as the waiting requests.
Minors (fixed):
- A fetch that settled late could overwrite newer keys. Only the newest fetch (a generation number) writes now.
- The poll loop is now capped by count as well as by the clock.
- There are tests for the backoff and for the late fetch. Both fail on the PR's first commit.
Validation at 8b1776f:
test/worker/access/**: 71 passed.- Live refusal walk: 1940 of 1940 refused.
yarn check: green.yarn test: the same 22 sandbox-bound failures as main.
Collaborator
Author
|
🤖 |
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.
The same fault #72 fixed for the Run data, in the Access key set of WP09 (#68): no request of a Worker isolate waits on the fetch of the Access keys that another request started.
Cause
remoteKeysinsrc/worker/access.tsis one per team domain and isolate (src/worker/access-entry.ts). It kept onependingpromise for the fetch ofhttps://<team>/cdn-cgi/access/certs, and every request that missed a kid awaited it.In workerd, a request that awaits a promise another request's I/O settles goes on in that request's I/O context, and its next I/O is refused ("Cannot perform I/O on behalf of a different request"). If the request that started the fetch was cancelled, the others could also wait forever.
What changed
The isolate keeps the parsed keys and the time of the last fetch, never a fetch.
Who fetches: the request that misses a kid fetches for itself, at most once per
JWKS_REFRESH_MS(10 s, as before).A fetch already in flight: a request that misses a kid while another request's fetch is in flight does not await it. It waits on a timer of its own, polling every
JWKS_POLL_MS(25 ms) for up toJWKS_WAIT_MS(3 s), for the keys that fetch leaves.A fetch that never settles stops counting as in flight after that time, and the request refuses the assertion. The default fetch has the same time limit (
AbortSignal.timeout(JWKS_WAIT_MS)), so "in flight" and "given up" agree.Only the newest fetch writes its result (a generation number), so a fetch that settles late never puts back older keys.
A failed fetch keeps nothing: the old keys stay. The next request may try again
JWKS_RETRY_MS(1 s) after the failure settled. The wait doubles for each failure in a row, up to the 10 s window. A made-up kid can still start at most one fetch per window while the team domain answers.Key rotation is unchanged: a kid miss after the window fetches again.
Regression tests,
test/worker/access/keys-request-scope.test.ts, in the style ofrequest-scope.test.ts:The first three fail on main's code (d20a7df). The backoff and late-fetch tests fail on this PR's first commit (096b571). The rotation test is a guard.
Evidence (owner's Mac, 30 Nov 2026)
test/worker/access/**, 71 passed (65 before, plus the 6 new).node test/worker/access/live.tsagainstwrangler devofnode test/worker/matrix-build.ts indexed, at 096b571 and again at 8b1776f, gives1940 of 1940 refused: 194 paths (191 built routes, 0 assets) x 5 attempts x GET, POST.wrangler.worker.jsonc, the gate refuses before any key is fetched.remoteKeysthere. The unit tests carry the fetch behaviour.yarn check: green.yarn testat 8b1776f: 3128 passed and 22 failed, in the same 5 files that fail on main in this sandbox (test/validate/workflow-run,test/rentgen/golden,test/proxy/check-sh,test/receipts/presets-r2,test/receipts/harness), which refusesmktempand the npm registry.