Skip to content

fix: mirror the legacy global dispatcher for built-in fetch#4962

Merged
mcollina merged 1 commit intomainfrom
fix/global-dispatcher-v1-mirror
Apr 3, 2026
Merged

fix: mirror the legacy global dispatcher for built-in fetch#4962
mcollina merged 1 commit intomainfrom
fix/global-dispatcher-v1-mirror

Conversation

@mcollina
Copy link
Copy Markdown
Member

@mcollina mcollina commented Apr 2, 2026

Summary

  • mirror setGlobalDispatcher() to Symbol.for('undici.globalDispatcher.1') on all supported Node.js versions, not only Node.js 22
  • keep storing Undici's dispatcher under Symbol.for('undici.globalDispatcher.2')
  • strengthen the regression test so it verifies Node.js global fetch actually uses the configured dispatcher
  • update the dispatcher docs to match the runtime behavior

Why

setGlobalDispatcher() in Undici v8 still needs to affect Node.js built-in fetch through the legacy .1 global dispatcher.

The current implementation only mirrors .1 on Node.js 22, which breaks the expected behavior on Node.js 24 and 25. That makes repros like setGlobalDispatcher(new EnvHttpProxyAgent()) stop affecting global fetch, even though manually setting Symbol.for('undici.globalDispatcher.1') still works there.

Fixes #4960.

Tests

  • npx borp -p "test/node-test/global-dispatcher-version.js"
  • /home/matteo/.nvm/versions/node/v22.21.1/bin/npx borp -p "test/node-test/global-dispatcher-version.js"
  • /home/matteo/.nvm/versions/node/v25.2.1/bin/npx borp -p "test/node-test/global-dispatcher-version.js"
  • npx eslint lib/global.js test/node-test/global-dispatcher-version.js

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.95%. Comparing base (dc4351a) to head (8eff526).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4962      +/-   ##
==========================================
+ Coverage   92.92%   92.95%   +0.02%     
==========================================
  Files         111      111              
  Lines       35831    35827       -4     
==========================================
+ Hits        33297    33303       +6     
+ Misses       2534     2524      -10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcollina mcollina merged commit ced6b01 into main Apr 3, 2026
33 checks passed
@mcollina mcollina deleted the fix/global-dispatcher-v1-mirror branch April 3, 2026 07:18
@github-actions github-actions Bot mentioned this pull request Apr 3, 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.

setGlobalDispatcher(new EnvHttpProxyAgent()) stopped working undici 8.0.0

3 participants