net: support sending net.BoundSocket to worker threads and child processes - #64725
net: support sending net.BoundSocket to worker threads and child processes#64725guybedford wants to merge 1 commit into
Conversation
|
Review requested:
|
88e7187 to
1fefa08
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #64725 +/- ##
==========================================
+ Coverage 90.13% 92.05% +1.91%
==========================================
Files 743 784 +41
Lines 242412 282711 +40299
Branches 45655 71504 +25849
==========================================
+ Hits 218510 260240 +41730
+ Misses 15403 13541 -1862
- Partials 8499 8930 +431
🚀 New features to boost your workflow:
|
1fefa08 to
d5b711d
Compare
|
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 <[email protected]>
b21b5f1 to
c05f5f9
Compare
c05f5f9 to
b21b5f1
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@guybedford This may need to be land manually |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Commit Queue failedThe pull request was removed from the Commit Queue and labeled
commit-queue-failed
Full Commit Queue output |
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 <[email protected]> PR-URL: #64725 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
|
Landed in f955c20 |
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.