Skip to content

Commit bc2111c

Browse files
juanarboltargos
authored andcommitted
src: make workers messaging more resilient
PR-URL: #38510 Fixes: #38499 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 2c66305 commit bc2111c

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

doc/api/errors.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,17 @@ Used when the main process is trying to read data from the child process's
715715
STDERR/STDOUT, and the data's length is longer than the `maxBuffer` option.
716716

717717
<a id="ERR_CLOSED_MESSAGE_PORT"></a>
718-
### ERR_CLOSED_MESSAGE_PORT
718+
### `ERR_CLOSED_MESSAGE_PORT`
719+
<!--
720+
added: REPLACEME
721+
changes:
722+
- version: 11.12.0
723+
pr-url: https://github.com/nodejs/node/pull/26487
724+
description: The error message was removed.
725+
- version: REPLACEME
726+
pr-url: https://github.com/nodejs/node/pull/38510
727+
description: The error message was reintroduced.
728+
-->
719729

720730
There was an attempt to use a `MessagePort` instance in a closed
721731
state, usually after `.close()` has been called.
@@ -2284,16 +2294,6 @@ removed: v12.5.0
22842294
The value passed to `postMessage()` contained an object that is not supported
22852295
for transferring.
22862296

2287-
<a id="ERR_CLOSED_MESSAGE_PORT"></a>
2288-
### `ERR_CLOSED_MESSAGE_PORT`
2289-
<!-- YAML
2290-
added: v10.5.0
2291-
removed: v11.12.0
2292-
-->
2293-
2294-
There was an attempt to use a `MessagePort` instance in a closed
2295-
state, usually after `.close()` has been called.
2296-
22972297
<a id="ERR_CRYPTO_HASH_DIGEST_NO_UTF16"></a>
22982298
### `ERR_CRYPTO_HASH_DIGEST_NO_UTF16`
22992299
<!-- YAML

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
const common = require('../common');
3-
const { MessageChannel } = require('worker_threads');
3+
const assert = require('assert');
4+
const { MessageChannel, moveMessagePortToContext } = require('worker_threads');
45

56
// Make sure that .start() and .stop() do not throw on closing/closed
67
// MessagePorts.
@@ -29,3 +30,12 @@ function dummy() {}
2930
port1.off('message', dummy);
3031
}));
3132
}
33+
34+
{
35+
const { port2 } = new MessageChannel();
36+
port2.close();
37+
assert.throws(() => moveMessagePortToContext(port2, {}), {
38+
code: 'ERR_CLOSED_MESSAGE_PORT',
39+
message: 'Cannot send data on closed MessagePort'
40+
});
41+
}

0 commit comments

Comments
 (0)