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 <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
juanarbol authored and targos committed May 30, 2021
1 parent a2c6b5f commit 016e46a
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 016e46a

Please sign in to comment.