Repository navigation
[v6.x] fix: handle frozen globalThis in setGlobalDispatcher (#5574) - #6018
Merged
metcoder95 merged 1 commit intoOct 16, 2026
Merged
Conversation
* fix: handle frozen globalThis in setGlobalDispatcher When Object.freeze(globalThis) is called before undici globals are accessed, setGlobalDispatcher would throw TypeError because it cannot extend globalThis. This fix wraps the Object.defineProperty calls in try/catch. When globalThis is not extensible (frozen), the dispatcher is stored in a module-level fallback variable instead. getGlobalDispatcher is updated to return the fallback dispatcher when the globalThis property is not available. This allows undici to work correctly even when globalThis has been frozen, which is recommended by Node.js security best practices (CWE-349). Fixes issue where Object.freeze(globalThis) breaks undici access. * test: add unit test for frozen globalThis in setGlobalDispatcher Add comprehensive test coverage for the frozen globalThis fix. Tests verify: 1. setGlobalDispatcher does not throw when globalThis is frozen 2. getGlobalDispatcher continues to return a valid dispatcher 3. The fallback mechanism works correctly when globalThis is not extensible This addresses the review feedback from mcollina requesting tests. * test: improve frozen globalThis test coverage Add comprehensive test cases to ensure all code paths in the frozen globalThis fix are exercised. Tests verify: 1. setGlobalDispatcher does not throw when globalThis is frozen 2. getGlobalDispatcher returns a valid dispatcher 3. Fallback dispatcher persists across multiple calls This addresses review feedback requesting tests. (cherry picked from commit a0922b0) Signed-off-by: Mrityunjay Pandey <mrityunjayp1409@gmail.com>
metcoder95
approved these changes
Oct 16, 2026
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.
This relates to...
Backport of #5574 to v6.x.
Rationale
On v6.x,
setGlobalDispatchercallsObject.defineProperty(globalThis, …)without a guard, so afterObject.freeze(globalThis), loading undici or setting a dispatcher throws aTypeError. The upstream testtest/global-frozen.jsfails 3 of 3 on v6.x.Changes
Dispatcher1Wrapper) global, solib/global.jsonly gets the part for the single dispatcher:try/catcharounddefinePropertythat stores the dispatcher in the fallback on aTypeError;getGlobalDispatcher()returning the fallback when the global property is missing.test/global-frozen.jsfrom fix: handle frozen globalThis in setGlobalDispatcher #5574 as is. It only useslib/globalandlib/dispatcher/agent, which exist on v6.x.Features
N/A
Bug Fixes
setGlobalDispatcher/getGlobalDispatcherwork whenglobalThisis frozen.Breaking Changes and Deprecations
N/A
Status
Tested locally on Linux with Node 24:
npm run test:unit(1045 tests, 1040 pass, 5 skipped, 0 fail) andnpm run lint.