Skip to content

Commit de474c8

Browse files
Trottjuanarbol
authored andcommitted
worker: do not send message if port is closing
Fixes: #42296 PR-URL: #42357 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent dcaed6d commit de474c8

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/node_messaging.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ void MessagePort::PostMessage(const FunctionCallbackInfo<Value>& args) {
964964
// Even if the backing MessagePort object has already been deleted, we still
965965
// want to serialize the message to ensure spec-compliant behavior w.r.t.
966966
// transfers.
967-
if (port == nullptr) {
967+
if (port == nullptr || port->IsHandleClosing()) {
968968
Message msg;
969969
USE(msg.Serialize(env, context, args[0], transfer_list, obj));
970970
return;

test/parallel/test-worker-message-port-close.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,11 @@ function dummy() {}
3939
message: 'Cannot send data on closed MessagePort'
4040
});
4141
}
42+
43+
// Refs: https://github.com/nodejs/node/issues/42296
44+
{
45+
const ch = new MessageChannel();
46+
ch.port1.onmessage = common.mustNotCall();
47+
ch.port2.close();
48+
ch.port2.postMessage('fhqwhgads');
49+
}

0 commit comments

Comments
 (0)