Skip to content

Commit

Permalink
inspector: fix session.disconnect crash
Browse files Browse the repository at this point in the history
  • Loading branch information
theanarkh committed Mar 14, 2023
1 parent 733ef4e commit 20c3a37
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/inspector_js_api.cc
Expand Up @@ -123,9 +123,11 @@ class JSBindingsConnection : public AsyncWrap {
new JSBindingsConnection(env, info.This(), callback);
}

// See https://github.com/nodejs/node/pull/46942
void Disconnect() {
session_.reset();
delete this;
BaseObjectPtr<JSBindingsConnection> strong_ref{this};
session_.reset();
Detach();
}

static void Disconnect(const FunctionCallbackInfo<Value>& info) {
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-inspector-connect-to-main-thread.js
@@ -0,0 +1,20 @@
'use strict';
const common = require('../common');

common.skipIfInspectorDisabled();

const { Session } = require('inspector');
const { Worker, isMainThread, workerData } = require('worker_threads');

if (!workerData) {
common.skipIfWorker();
}

if (isMainThread) {
new Worker(__filename, { workerData: {} });
} else {
const session = new Session();
session.connectToMainThread();
// Do not crash
session.disconnect();
}

0 comments on commit 20c3a37

Please sign in to comment.