Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
inspector: fix session.disconnect crash
PR-URL: #46942
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
theanarkh authored and targos committed Mar 18, 2023
1 parent a5ebc89 commit f6ec81d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion 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() {
BaseObjectPtr<JSBindingsConnection> strong_ref{this};
session_.reset();
delete this;
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 f6ec81d

Please sign in to comment.