inspector: fix session.disconnect crash

PR-URL: https://github.com/nodejs/node/pull/46942
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
theanarkh 2023-03-15 07:27:27 +08:00 committed by GitHub
parent 115c9ac68d
commit f543c054fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -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) {

View File

@ -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();
}