Repository navigation
In review
Labels
workerIssues and PRs related to the worker_threads module and Worker API.
Description
Version
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 transferred
const { MessageChannel, receiveMessageOnPort } = require('node:worker_threads');
const { port1 } = new MessageChannel();
const other = new MessageChannel();
other.port1.postMessage(null, [port1]);
receiveMessageOnPort(port1); // Segmentation fault// 2. structuredClone() (without transfer) of a port whose close has completed
const { MessageChannel } = require('node:worker_threads');
const { port1 } = new MessageChannel();
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)returnsundefined, the same as for a port whose close has completed (MessagePort::ReceiveMessagealready returnsno_message_symbolwhenUnwrap()givesnullptr).structuredClone(port1)throws aDataCloneError. The transfer-list path already handles this case:structuredClone(port1, { transfer: [port1] })throws "MessagePort in transfer list is already detached". Posting a port right afterclose(), as in port.postMessage with another closed port results in an abort #56362, also throws aDataCloneError("Cannot clone object of unsupported type.") on v26.13.1.
What do you see instead?
Segmentation fault (exit code 139).
Additional information
MessagePort::TransferForMessaging()callsClose()and thenDetach(), which leavesdata_null while the handle is still closing, soUnwrap()still returns the port.MessagePort::ReceiveMessage(const FunctionCallbackInfo<Value>&)then callsport->ReceiveMessage(...), which locksdata_->mutex_without checkingdata_. Adata_check before that call (returningno_message_symbol, asStart()andStop()already do) fixes it.- After the close completes, the
BaseObjectis deleted but the object still passesBaseObject::IsBaseObject(), soSerializerDelegate::IsHostObject()reports it as a host object.WriteHostObject(Isolate*, Local<Object>)passesUnwrap<BaseObject>(object)on without a null check, andWriteHostObject(BaseObjectPtr<BaseObject>)callshost_object->GetTransferMode()onnullptr. Treating a nullhost_objectaskDisallowCloneAndTransfer(throwing "Cannot clone object of unsupported type.") fixes it.
The code is the same on main (be0f17c).
Metadata
Metadata
Assignees
Labels
workerIssues and PRs related to the worker_threads module and Worker API.
Activity
yohannesjoya commentedon Nov 26, 2026
Reproduced both cases on Linux x64: each script crashes with SIGSEGV on v20.20.2, v22.20.0, v24.22.3, v25.6.1 and main (built from d2812af), so this isn't a recent regression.
The backtraces on main match the analysis above: case 1 faults in
uv_mutex_lockwith mutex address0x8(a nulldata_) fromMessagePort::ReceiveMessage, and case 2 faults inSerializerDelegate::WriteHostObject.