GeezerVison is showing github.com — inspector: fix session.disconnect crash · nodejs/node@f6ec81d
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/inspector_js_api.cc +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -123,9 +123,11 @@ class JSBindingsConnection : public AsyncWrap { |
123 | 123 | new JSBindingsConnection(env, info.This(), callback); |
124 | 124 | } |
125 | 125 |
|
| 126 | + // See https://github.com/nodejs/node/pull/46942 |
126 | 127 | void Disconnect() { |
| 128 | + BaseObjectPtr<JSBindingsConnection> strong_ref{this}; |
127 | 129 | session_.reset(); |
128 | | - delete this; |
| 130 | + Detach(); |
129 | 131 | } |
130 | 132 |
|
131 | 133 | static void Disconnect(const FunctionCallbackInfo<Value>& info) { |
|
Collapse file
Copy file name to clipboard +20Lines changed: 20 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | + |
| 4 | +common.skipIfInspectorDisabled(); |
| 5 | + |
| 6 | +const { Session } = require('inspector'); |
| 7 | +const { Worker, isMainThread, workerData } = require('worker_threads'); |
| 8 | + |
| 9 | +if (!workerData) { |
| 10 | + common.skipIfWorker(); |
| 11 | +} |
| 12 | + |
| 13 | +if (isMainThread) { |
| 14 | + new Worker(__filename, { workerData: {} }); |
| 15 | +} else { |
| 16 | + const session = new Session(); |
| 17 | + session.connectToMainThread(); |
| 18 | + // Do not crash |
| 19 | + session.disconnect(); |
| 20 | +} |