Skip to content

Commit

Permalink
src: make workers messaging more resilient
Browse files Browse the repository at this point in the history
PR-URL: #38510
Fixes: #38499
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
juanarbol authored and targos committed Jun 11, 2021
1 parent 2c66305 commit bc2111c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
22 changes: 11 additions & 11 deletions doc/api/errors.md
Expand Up @@ -715,7 +715,17 @@ Used when the main process is trying to read data from the child process's
STDERR/STDOUT, and the data's length is longer than the `maxBuffer` option.

<a id="ERR_CLOSED_MESSAGE_PORT"></a>
### ERR_CLOSED_MESSAGE_PORT
### `ERR_CLOSED_MESSAGE_PORT`
<!--
added: REPLACEME
changes:
- version: 11.12.0
pr-url: https://github.com/nodejs/node/pull/26487
description: The error message was removed.
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/38510
description: The error message was reintroduced.
-->

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

<a id="ERR_CLOSED_MESSAGE_PORT"></a>
### `ERR_CLOSED_MESSAGE_PORT`
<!-- YAML
added: v10.5.0
removed: v11.12.0
-->

There was an attempt to use a `MessagePort` instance in a closed
state, usually after `.close()` has been called.

<a id="ERR_CRYPTO_HASH_DIGEST_NO_UTF16"></a>
### `ERR_CRYPTO_HASH_DIGEST_NO_UTF16`
<!-- YAML
Expand Down
12 changes: 11 additions & 1 deletion test/parallel/test-worker-message-port-close.js
@@ -1,6 +1,7 @@
'use strict';
const common = require('../common');
const { MessageChannel } = require('worker_threads');
const assert = require('assert');
const { MessageChannel, moveMessagePortToContext } = require('worker_threads');

// Make sure that .start() and .stop() do not throw on closing/closed
// MessagePorts.
Expand Down Expand Up @@ -29,3 +30,12 @@ function dummy() {}
port1.off('message', dummy);
}));
}

{
const { port2 } = new MessageChannel();
port2.close();
assert.throws(() => moveMessagePortToContext(port2, {}), {
code: 'ERR_CLOSED_MESSAGE_PORT',
message: 'Cannot send data on closed MessagePort'
});
}

0 comments on commit bc2111c

Please sign in to comment.