Skip to content

Pool loses caller's AsyncLocalStorage context for queued HTTPS requests (Undici 8) #5981

Open

Description

@kettanaito

Bug Description

Reproduction

Standalone reproduction script:

'use strict'

import { AsyncLocalStorage } from 'node:async_hooks'
import { subscribe } from 'node:diagnostics_channel'

const storage = new AsyncLocalStorage()

subscribe('undici:request:create', ({ request }) => {
  console.log(request.path, '→', storage.getStore())
})

await Promise.all(
  ['a', 'b', 'c'].map((name) =>
    storage.run(name, () => fetch(`https://example.com/${name}`)),
  ),
)

Steps to reproduce (if not using the script above):

Expected Behavior

/a → a
/b → b
/c → c

Every request dispatches in the async context of its own fetch() / request() caller, whether it was sent immediately or queued behind the connection probe.

Actual Behavior

/a → a
/b → a
/c → a

Same with request() from the undici package. Only https: origins are affected. http://example.com prints a, b, c correctly on the same version. Cause: Pool defers /b and /c until /a's connection finishes ALPN negotiation, then dispatches them from /a's connect callback, so they inherit /a's async context.

Logs & Screenshots

Environment

  • OS:
  • Node.js version:
  • undici version:

Additional context

Discovered in a test failure in MSW (see job) after Undici introduced changes in Node.js v26 (passes in v22 and v24).

Activity

  1. kettanaito commented on Oct 8, 2026

    @kettanaito
    ContributorAuthor

    Let me know if this sounds like something Undici should fix. We rely on ALS in MSW for various reasons and this breaks the fetch interception for us on Node.js v26. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions