Skip to content

Commit

Permalink
worker: do not send message if port is closing
Browse files Browse the repository at this point in the history
Fixes: #42296
  • Loading branch information
Trott committed Mar 16, 2022
1 parent 4586ac4 commit f53281d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/node_messaging.cc
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
7 changes: 7 additions & 0 deletions test/parallel/test-worker-message-port-close.js
Expand Up @@ -39,3 +39,10 @@ function dummy() {}
message: 'Cannot send data on closed MessagePort'
});
}

{
const ch = new MessageChannel()
ch.port1.onmessage = common.mustNotCall();
ch.port2.close();
ch.port2.postMessage('fhqwhgads');
}

0 comments on commit f53281d

Please sign in to comment.