summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/handle_wrap.h4
-rw-r--r--test/parallel/test-worker-message-port-inspect-during-init-hook.js21
2 files changed, 24 insertions, 1 deletions
diff --git a/src/handle_wrap.h b/src/handle_wrap.h
index 612874aa2e..a555da9479 100644
--- a/src/handle_wrap.h
+++ b/src/handle_wrap.h
@@ -61,7 +61,9 @@ class HandleWrap : public AsyncWrap {
static void HasRef(const v8::FunctionCallbackInfo<v8::Value>& args);
static inline bool IsAlive(const HandleWrap* wrap) {
- return wrap != nullptr && wrap->state_ != kClosed;
+ return wrap != nullptr &&
+ wrap->IsDoneInitializing() &&
+ wrap->state_ != kClosed;
}
static inline bool HasRef(const HandleWrap* wrap) {
diff --git a/test/parallel/test-worker-message-port-inspect-during-init-hook.js b/test/parallel/test-worker-message-port-inspect-during-init-hook.js
new file mode 100644
index 0000000000..30b90710a6
--- /dev/null
+++ b/test/parallel/test-worker-message-port-inspect-during-init-hook.js
@@ -0,0 +1,21 @@
+'use strict';
+const common = require('../common');
+const util = require('util');
+const assert = require('assert');
+const async_hooks = require('async_hooks');
+const { MessageChannel } = require('worker_threads');
+
+// Regression test: Inspecting a `MessagePort` object before it is finished
+// constructing does not crash the process.
+
+async_hooks.createHook({
+ init: common.mustCall((id, type, triggerId, resource) => {
+ assert.strictEqual(util.inspect(resource),
+ 'MessagePort { active: true, refed: false }');
+ }, 2)
+}).enable();
+
+const { port1 } = new MessageChannel();
+const inspection = util.inspect(port1);
+assert(inspection.includes('active: true'));
+assert(inspection.includes('refed: false'));