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 de474c8

Browse filesBrowse files
Trottjuanarbol
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 dcaed6d commit de474c8
Copy full SHA for de474c8

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
@@ -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;
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.