net: support sending net.BoundSocket to worker threads and child processes - #64725
Open
guybedford wants to merge 1 commit into
Open
net: support sending net.BoundSocket to worker threads and child processes#64725guybedford wants to merge 1 commit into
guybedford wants to merge 1 commit into
Conversation
Collaborator
|
Review requested:
|
guybedford
force-pushed
the
boundsocket-transfer
branch
from
July 25, 2026 01:48
88e7187 to
1fefa08
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #64725 +/- ##
========================================
Coverage 90.13% 90.14%
========================================
Files 743 744 +1
Lines 242412 242612 +200
Branches 45655 45697 +42
========================================
+ Hits 218510 218693 +183
- Misses 15403 15418 +15
- Partials 8499 8501 +2
🚀 New features to boost your workflow:
|
guybedford
force-pushed
the
boundsocket-transfer
branch
from
July 27, 2026 19:39
1fefa08 to
d5b711d
Compare
Contributor
Author
|
I've updated this PR to also include support for transferring a BoundSocket to a child process. |
This adds support for transferring net.BoundSocket instances to other threads via the worker_threads postMessage() transfer list, and for sending them to child processes as the sendHandle argument of subprocess.send(), following on from the BoundSocket introduction. A BoundSocket reserves a port synchronously at construction time. Making it transferable means a port can be reserved on one thread or process and the bound (but not yet listening or connected) TCP handle handed off to another to listen or connect on, without racing on the bind. For threads, BoundSocket implements kTransfer/kTransferList/ kDeserialize, moving the underlying TCP handle with the same mechanism used for net.Socket and net.Server transfer. For child processes, the handleConversion entry reuses the same transfer protocol on the sending side and the same _TransferredBoundSocket deserialization path on the receiving side; the underlying transport is that of cluster's shared-handle scheduling: SCM_RIGHTS on Unix and WSADuplicateSocket on Windows, both of which carry bind state. In both cases the source instance is left in the adopted state: address(), fd() and close() throw ERR_SOCKET_HANDLE_ADOPTED. Transfer requires an un-adopted, open TCP handle, otherwise ERR_WORKER_HANDLE_NOT_TRANSFERABLE is thrown; pipe (path) binds are not transferable and throw ERR_INVALID_HANDLE_TYPE when sent over IPC. On the receiving side the local address is re-derived from the handle rather than trusted from serialized state. Signed-off-by: Guy Bedford <guybedford@gmail.com>
guybedford
force-pushed
the
boundsocket-transfer
branch
2 times, most recently
from
July 27, 2026 21:02
b21b5f1 to
c05f5f9
Compare
guybedford
force-pushed
the
boundsocket-transfer
branch
from
July 27, 2026 21:05
c05f5f9 to
b21b5f1
Compare
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 adds support for transferring
net.BoundSocketinstances to other threads via theworker_threadspostMessage()transfer list, and for sending them to child processes as thesendHandleargument ofsubprocess.send(), following on from #64399 and #64460.A
BoundSocketreserves a port synchronously at construction time. Making it transferable means a port can be reserved on one thread or process and the bound handle handed off to another to listen or connect on, without racing on the bind.BoundSocketimplements[kTransfer]/[kTransferList]/[kDeserialize], moving the underlying TCP handle with the same mechanism used fornet.Socketandnet.Servertransfer.subprocess.send()/process.send()accept aBoundSocketassendHandle: thehandleConversionentry reuses the transfer protocol on the sending side and the_TransferredBoundSocketdeserialization path on the receiving side. The transport is the same as cluster's shared-handle scheduling (SCM_RIGHTSon Unix,WSADuplicateSocketon Windows), both of which carry bind state.address(),fd()andclose()throwERR_SOCKET_HANDLE_ADOPTED.ERR_WORKER_HANDLE_NOT_TRANSFERABLEis thrown. Pipe (path) binds are not transferable, and throwERR_INVALID_HANDLE_TYPEwhen sent over IPC.Tests cover a parent-to-worker transfer and a parent-to-child-process send where the receiver listens on the transferred bind, plus guard cases (closed, adopted and pipe-bound sockets). Docs updated in net.md, worker_threads.md, child_process.md and errors.md.