Repository navigation
fix(pool): keep caller async context for queued requests - #5982
Merged
Merged
Conversation
Requests waiting in the Pool queue were dispatched from whichever callback drained it (another request's connect or drain), so Client#dispatch and the undici:request:create diagnostics channel ran in the wrong AsyncLocalStorage context. Since #5799 every concurrent HTTPS request is queued during ALPN negotiation, which made this hit fetch() by default. Capture the caller's async context when queueing and dispatch inside it. Fixes: #5981 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PU6gYCHEgVgF9WeVje8SXF Signed-off-by: Matteo Collina <hello@matteocollina.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5982 +/- ##
==========================================
+ Coverage 91.53% 91.54% +0.01%
==========================================
Files 113 113
Lines 43597 43614 +17
==========================================
+ Hits 39908 39928 +20
+ Misses 3689 3686 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
kettanaito
approved these changes
Oct 9, 2026
kettanaito
left a comment
Contributor
There was a problem hiding this comment.
FWIW, looks good! Thank you so much for covering it promptly.
metcoder95
approved these changes
Oct 19, 2026
langz
added a commit
to dnbexperience/eufemia
that referenced
this pull request
Oct 22, 2026
`jsdom` 30.1.1 requests `undici` `^8.10.2`, which was locked to 8.12.2. This moves that one lockfile entry to 8.12.3. No other package changes. 8.12.3 has two runtime fixes: - An HTTP/2 connection that stops responding after a stream timeout is now replaced ([nodejs/undici#6052](nodejs/undici#6052)). - Queued pool requests keep the caller's async context ([nodejs/undici#5982](nodejs/undici#5982)). The rest of the release is CI, docs and types. It has no security fixes: every advisory in undici's own repository is already fixed in 8.12.2. `undici` 8 is only used by `jsdom` (our test environment), so nothing that we ship changes. **Verified locally** - **Tests:** 2,365 `@dnb/eufemia` tests in the jsdom environment pass on both `main` and this branch. They cover `button`, `input`, `dropdown`, `autocomplete`, `date-picker`, `table`, `dialog`, `upload`, `shared` and the Forms `Handler`. The portal tests pass too: 880 of 880 on this branch. On `main`, 879 of 880 passed, and the one failure was the known `inject-scope` 5 s timeout. - **A real network check through jsdom:** jsdom loads a page, an external script and 20 parallel XHR requests from a local server. It passes on 8.12.2 and on 8.12.3 (the 8.12.2 copy came from the registry and its checksum matches). As a control, I broke `pool-base.js` on purpose, and the check then failed with that error. So the check goes through undici's request pool, which is one of the two changed files. - The package has no dependencies and no install scripts. Its Node requirement is unchanged (`>=22.19.0`), and the repo uses Node 24.20. - `yarn install --immutable`, `yarn dedupe --check`, `lint:resolutions` and the three `audit:ci` workspaces pass.
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.
Fixes #5981
Problem
Requests that wait in the Pool queue are dispatched later from whichever callback drains it (another request's
connectordrainevent).Client#dispatch, and theundici:request:creatediagnostics channel it publishes, therefore ran in that callback'sAsyncLocalStoragecontext instead of the caller's.This was already the case for saturated pools (e.g.
connections: 1), but since #5799 every concurrent HTTPS request is held in the Pool queue until the first connection completes ALPN negotiation, so it now affectsfetch()against anyhttps:origin by default (h1 and h2 servers alike). MSW relies on this context and broke on Node.js v26.Fix
Queued requests are stored as a small
AsyncResourcesubclass that captures the caller's context, and are dispatched inside it when the queue drains. Requests dispatched directly to a free client are unaffected.BalancedPoolsharesPoolBase, so it is covered too.Tests
test/issue-5981.jscovers HTTPS h1, HTTPS h2 (queued during ALPN) and HTTP Pool withconnections: 1. All three fail without the fix and pass with it.🤖 Generated with Claude Code
https://claude.ai/code/session_01PU6gYCHEgVgF9WeVje8SXF