Skip to content

Commit

Permalink
inspector: fix session.disconnect crash
Browse files Browse the repository at this point in the history
PR-URL: #46942
Reviewed-By: Juan José Arboleda <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
theanarkh authored and danielleadams committed Jul 6, 2023
1 parent ddf819f commit 6099d2d
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
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,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
Original file line number Diff line number Diff line change
@@ -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 6099d2d

Please sign in to comment.