Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/node_messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ void MessagePort::PostMessage(const FunctionCallbackInfo<Value>& args) {
// Even if the backing MessagePort object has already been deleted, we still
// want to serialize the message to ensure spec-compliant behavior w.r.t.
// transfers.
if (port == nullptr) {
if (port == nullptr || port->IsHandleClosing()) {
Message msg;
USE(msg.Serialize(env, context, args[0], transfer_list, obj));
return;
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-worker-message-port-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ function dummy() {}
message: 'Cannot send data on closed MessagePort'
});
}

// Refs: https://github.com/nodejs/node/issues/42296
{
const ch = new MessageChannel();
ch.port1.onmessage = common.mustNotCall();
ch.port2.close();
ch.port2.postMessage('fhqwhgads');
}