You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MessagePort: segfault in receiveMessageOnPort() on a transferred port and in structuredClone() of a closed port #67766
v26.13.1 (v24.22.3 and v22.23.5 crash the same way)
Platform
Linux x64 and arm64 (official node:26.13.1-bookworm-slim image) and macOS arm64 (official v26.13.1 binary); v24.22.3 and v22.23.5 checked on Linux x64
Subsystem
worker_threads / messaging
What steps will reproduce the bug?
Two separate scripts. Each one crashes the process with SIGSEGV.
// 1. receiveMessageOnPort() on a port that was just transferredconst{ MessageChannel, receiveMessageOnPort }=require('node:worker_threads');const{ port1 }=newMessageChannel();constother=newMessageChannel();other.port1.postMessage(null,[port1]);receiveMessageOnPort(port1);// Segmentation fault
// 2. structuredClone() (without transfer) of a port whose close has completedconst{ MessageChannel }=require('node:worker_threads');const{ port1 }=newMessageChannel();port1.close(()=>{setImmediate(()=>structuredClone(port1));// Segmentation fault});
How often does it reproduce? Is there a required condition?
Always.
What is the expected behavior? Why is that the expected behavior?
receiveMessageOnPort(port1) returns undefined, the same as for a port whose close has completed (MessagePort::ReceiveMessage already returns no_message_symbol when Unwrap() gives nullptr).
structuredClone(port1) throws a DataCloneError. The transfer-list path already handles this case: structuredClone(port1, { transfer: [port1] }) throws "MessagePort in transfer list is already detached". Posting a port right after close(), as in port.postMessage with another closed port results in an abort #56362, also throws a DataCloneError ("Cannot clone object of unsupported type.") on v26.13.1.
What do you see instead?
Segmentation fault (exit code 139).
Additional information
MessagePort::TransferForMessaging() calls Close() and then Detach(), which leaves data_ null while the handle is still closing, so Unwrap() still returns the port. MessagePort::ReceiveMessage(const FunctionCallbackInfo<Value>&) then calls port->ReceiveMessage(...), which locks data_->mutex_ without checking data_. A data_ check before that call (returning no_message_symbol, as Start() and Stop() already do) fixes it.
After the close completes, the BaseObject is deleted but the object still passes BaseObject::IsBaseObject(), so SerializerDelegate::IsHostObject() reports it as a host object. WriteHostObject(Isolate*, Local<Object>) passes Unwrap<BaseObject>(object) on without a null check, and WriteHostObject(BaseObjectPtr<BaseObject>) calls host_object->GetTransferMode() on nullptr. Treating a null host_object as kDisallowCloneAndTransfer (throwing "Cannot clone object of unsupported type.") fixes it.
Activity