Skip to content

fix: support frozen globalThis - #72

Merged
ronag merged 1 commit into
nxtedition:masterfrom
ronag:codex/fix-frozen-globalthis-20260829
Aug 30, 2026
Merged

fix: support frozen globalThis#72
ronag merged 1 commit into
nxtedition:masterfrom
ronag:codex/fix-frozen-globalthis-20260829

Conversation

@ronag

@ronag ronag commented Aug 29, 2026

Copy link
Copy Markdown
Member

Summary

  • adapt fix: handle frozen globalThis in setGlobalDispatcher nodejs/undici#5574 so importing and configuring the lower fork works when globalThis is frozen
  • preserve setGlobalDispatcher() / getGlobalDispatcher() replacement semantics when the freeze happens either before import or after the initial dispatcher is published
  • keep the custom live-socket registry usable when a frozen global cannot accept its symbol and legacy-alias properties
  • cover both freeze timings in isolated child processes, including dispatcher identity and socket registration/removal

Upstream fix: nodejs#5574

Validation

Exact head: 286f1dabc3a5020fdcc276e3381e449731ebb66f on Node.js v26.7.0

  • frozen-global regression: 2 passed
  • socket-registry regression: 4 passed
  • Agent/global-dispatcher regression: 25 passed
  • full npm test: unit 576 passed, 6 skipped; node-test 151 passed; type tests passed
  • npm run lint
  • git diff --check

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens Undici’s global dispatcher and live-socket registry publishing logic to work correctly when globalThis is frozen, and adds regression tests to cover freezing both before and after import.

Changes:

  • Add a module-local fallback dispatcher in lib/global.js so setGlobalDispatcher() / getGlobalDispatcher() continue to work when globalThis cannot be mutated.
  • Make the socket registry resilient to non-extensible/frozen globals by avoiding ??= publication to a Symbol.for slot when the global cannot accept new properties, while keeping the legacy alias behavior when possible.
  • Add isolated child-process tests covering both “freeze before import” and “freeze after import” scenarios, including dispatcher identity and socket tracking/removal.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
test/global-frozen.js Runs a fixture in two freeze phases to validate frozen-global behavior in isolated processes.
test/fixtures/frozen-global.js Exercises dispatcher replacement semantics and socket registry behavior under a frozen globalThis.
lib/global.js Introduces a fallback dispatcher path when defining the global symbol property fails due to a frozen/non-extensible global.
lib/core/socket-registry.js Avoids publishing new global symbol/alias properties when globalThis is non-extensible, while preserving cross-copy sharing when already published.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ronag
ronag marked this pull request as ready for review August 29, 2026 20:15
@ronag
ronag merged commit bd2064e into nxtedition:master Aug 30, 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.

2 participants