Skip to content

Commit 2c66305

Browse files
juanarboltargos
authored andcommitted
Revert "worker: remove ERR_CLOSED_MESSAGE_PORT"
This reverts commit 73370b4. The unit test is preserved to make sure it does not break #26463 again. 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 cea8b42 commit 2c66305

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

doc/api/errors.md

+6
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,12 @@ Used when a child process is being forked without specifying an IPC channel.
714714
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

717+
<a id="ERR_CLOSED_MESSAGE_PORT"></a>
718+
### ERR_CLOSED_MESSAGE_PORT
719+
720+
There was an attempt to use a `MessagePort` instance in a closed
721+
state, usually after `.close()` has been called.
722+
717723
<a id="ERR_CONSOLE_WRITABLE_STREAM"></a>
718724
### `ERR_CONSOLE_WRITABLE_STREAM`
719725

src/node_errors.h

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ void OnFatalError(const char* location, const char* message);
3232
V(ERR_BUFFER_CONTEXT_NOT_AVAILABLE, Error) \
3333
V(ERR_BUFFER_OUT_OF_BOUNDS, RangeError) \
3434
V(ERR_BUFFER_TOO_LARGE, Error) \
35+
V(ERR_CLOSED_MESSAGE_PORT, Error) \
3536
V(ERR_CONSTRUCT_CALL_REQUIRED, TypeError) \
3637
V(ERR_CONSTRUCT_CALL_INVALID, TypeError) \
3738
V(ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH, RangeError) \
@@ -98,6 +99,7 @@ ERRORS_WITH_CODE(V)
9899
#define PREDEFINED_ERROR_MESSAGES(V) \
99100
V(ERR_BUFFER_CONTEXT_NOT_AVAILABLE, \
100101
"Buffer is not available for the current Context") \
102+
V(ERR_CLOSED_MESSAGE_PORT, "Cannot send data on closed MessagePort") \
101103
V(ERR_CONSTRUCT_CALL_INVALID, "Constructor cannot be called") \
102104
V(ERR_CONSTRUCT_CALL_REQUIRED, "Cannot call constructor without `new`") \
103105
V(ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH, \

src/node_messaging.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,11 @@ void MessagePort::MoveToContext(const FunctionCallbackInfo<Value>& args) {
10401040
"The \"port\" argument must be a MessagePort instance");
10411041
}
10421042
MessagePort* port = Unwrap<MessagePort>(args[0].As<Object>());
1043-
CHECK_NOT_NULL(port);
1043+
if (port == nullptr || port->IsHandleClosing()) {
1044+
Isolate* isolate = env->isolate();
1045+
THROW_ERR_CLOSED_MESSAGE_PORT(isolate);
1046+
return;
1047+
}
10441048

10451049
Local<Value> context_arg = args[1];
10461050
ContextifyContext* context_wrapper;

0 commit comments

Comments
 (0)