Skip to content

Key weak collections by net sockets and servers, and carry the socket in undici client diagnostics - #1742

Merged
ctate merged 1 commit into
mainfrom
opt/undici-socket-identity
Oct 22, 2026
Merged

ctate merged 1 commit into
mainfrom
opt/undici-socket-identity

Conversation

@cramforce

Copy link
Copy Markdown
Contributor

Key weak collections by net sockets and servers, and carry the socket in undici client diagnostics

Summary

  • WeakMap and WeakSet keys. net.Socket and net.Server values can now key weak collections by identity. Before, they failed at run time with "Weak collection keys of this native reference type have no weak lifetime lowering". Releasing a socket or server notifies the weak-dispose hook, so its entries go away with it. The hook is set only in programs that create a weak collection, so other net programs pay one predictable branch per release.
  • Handles inside messages. A record holding a runtime handle, such as a socket in a diagnostics_channel message, now converts to a checked-dynamic value, with the handle boxed by reference. A bare handle already converted this way. Before, publishing { socket } was refused at compile time.
  • undici client diagnostics. The built-in undici publishes socket on undici:client:connected and undici:client:sendHeaders. It is the same socket the connector returned. It also publishes connector on beforeConnect, connected and connectError, matching undici 5 and 7. As in undici, connectError carries no socket.

Evidence

Each program runs under Node and as a native binary, and the outputs must match.

  • Corpus 6620-weak-keys-net-sockets covers:
    • WeakMap and WeakSet keyed by client sockets, server-side sockets and a server;
    • the same socket read back out of a published message;
    • delete;
    • the TypeError for a primitive key.
  • npm cases undici5 and undici7 subscribe to the client channels and key a WeakMap<Socket, …> by each message's socket. Both under Node and natively, 12 messages carry the socket the wrapped connector returned and none carries another.
  • The sanitized lane passes the new program and both undici cases. Lint and format are clean, and there is one new ts7 baseline.

Zero cost

Zero-cost gate against the base (3,498 programs: bench, self and the whole corpus):

  • IR and LLVM are identical for every program, including the self-compile.
  • The gate flagged one IR change, in fs-extra-package. That program compiles to identical IR, LLVM and executable when built directly from both trees, so the flag was build nondeterminism.
  • Executable-only differences:
    • 133 net programs grow inside the socket and server release functions (the dispose branch);
    • 27 programs that link the weak-key check have a byte-level difference in it;
    • 1 program differs in a few bytes of scr_cyc_thread.
  • Run time: bench geomean -0.27% and self +0.03%, both within tolerance.

🤖 Generated with Claude Code

… in undici client diagnostics

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
scriptc Ready Ready Preview, v0 Oct 22, 2026 3:07am UTC

@ctate
ctate merged commit 2a48d46 into main Oct 22, 2026
42 of 64 checks passed
@ctate
ctate deleted the opt/undici-socket-identity branch October 22, 2026 03:14

This branch was successfully deployed

1 active deployment
Preview — fc551c4a Deployed Oct 22, 2026 by vercel[bot]
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