From c4233b41994772a3af15fe49432087c2a56931ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Arboleda?= Date: Sun, 2 May 2021 22:43:08 -0500 Subject: [PATCH] src: make workers messaging more resilient --- src/node_errors.h | 2 ++ src/node_messaging.cc | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/node_errors.h b/src/node_errors.h index 291365fa3b4dc96..050fb298877116a 100644 --- a/src/node_errors.h +++ b/src/node_errors.h @@ -80,6 +80,7 @@ void OnFatalError(const char* location, const char* message); V(ERR_VM_MODULE_LINK_FAILURE, Error) \ V(ERR_WASI_NOT_STARTED, Error) \ V(ERR_WORKER_INIT_FAILED, Error) \ + V(ERR_WORKER_MESSAGEPORT_CLOSED, Error) \ V(ERR_PROTO_ACCESS, Error) #define V(code, type) \ @@ -166,6 +167,7 @@ ERRORS_WITH_CODE(V) V(ERR_TLS_PSK_SET_IDENTIY_HINT_FAILED, "Failed to set PSK identity hint") \ V(ERR_WASI_NOT_STARTED, "wasi.start() has not been called") \ V(ERR_WORKER_INIT_FAILED, "Worker initialization failure") \ + V(ERR_WORKER_MESSAGEPORT_CLOSED, "Worker messageport closed") \ V(ERR_PROTO_ACCESS, \ "Accessing Object.prototype.__proto__ has been " \ "disallowed with --disable-proto=throw") diff --git a/src/node_messaging.cc b/src/node_messaging.cc index fbe6c407a6cea22..fd853d36f7e6e64 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -1065,7 +1065,11 @@ void MessagePort::MoveToContext(const FunctionCallbackInfo& args) { "The \"port\" argument must be a MessagePort instance"); } MessagePort* port = Unwrap(args[0].As()); - CHECK_NOT_NULL(port); + if (port == nullptr) { + Isolate* isolate = env->isolate(); + THROW_ERR_WORKER_MESSAGEPORT_CLOSED(isolate); + return; + } Local context_arg = args[1]; ContextifyContext* context_wrapper;