Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 229fb40

Browse filesBrowse files
Trottbengl
authored andcommitted
worker: do not send message if port is closing
Fixes: #42296 PR-URL: #42357 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent b82bac0 commit 229fb40
Copy full SHA for 229fb40

File tree

Expand file treeCollapse file tree

2 files changed

+9
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+9
-1
lines changed
Open diff view settings
Collapse file

‎src/node_messaging.cc‎

Copy file name to clipboardExpand all lines: src/node_messaging.cc
+1-1Lines changed: 1 addition & 1 deletion
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;
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-worker-message-port-close.js
+8Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.