Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: fix inspecting MessagePort from init async hook #31600

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/handle_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 21 additions & 0 deletions test/parallel/test-worker-message-port-inspect-during-init-hook.js
Original file line number Diff line number Diff line change
@@ -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'));