Skip to content

Commit 229fb40

Browse files
Trottbengl
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 b82bac0 commit 229fb40

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/node_messaging.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ void MessagePort::PostMessage(const FunctionCallbackInfo<Value>& args) {
980980
// Even if the backing MessagePort object has already been deleted, we still
981981
// want to serialize the message to ensure spec-compliant behavior w.r.t.
982982
// transfers.
983-
if (port == nullptr) {
983+
if (port == nullptr || port->IsHandleClosing()) {
984984
Message msg;
985985
USE(msg.Serialize(env, context, args[0], transfer_list, obj));
986986
return;

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

+8
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)