Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/internal/debugger/inspect_probe.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,8 @@ class ProbeInspectorSession {

async callCdp(method, params, probe = null) {
if (this.finished) { throw kInspectorFailedSentinel; }
this.inFlight = { __proto__: null, method, probe };
const request = { __proto__: null, method, probe };
this.inFlight = request;
debug('CDP -> %s%s', method, probe !== null ? `, probe=${probe.index}` : '');
try {
const result = await this.client.callMethod(method, params);
Expand Down Expand Up @@ -763,7 +764,9 @@ class ProbeInspectorSession {
}
throw kInspectorFailedSentinel;
} finally {
this.inFlight = null;
if (this.inFlight === request) {
this.inFlight = null;
}
}
}

Expand Down
60 changes: 60 additions & 0 deletions test/parallel/test-debugger-probe-overlapping-cdp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Flags: --expose-internals
// This tests that completing an older CDP request does not clear the state of
// a newer request started while handling a reentrant Debugger.paused event.
'use strict';

const common = require('../common');
common.skipIfInspectorDisabled();

const assert = require('assert');
const { ProbeInspectorSession } = require('internal/debugger/inspect_probe');

@joyeecheung joyeecheung Jul 13, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should test the internals this way, a test for debugger feature should be E2E and if the state needed can't be reproduced with user-reachable operations, it should not manufacture the state to avoid overfit assumptions that become maintenance burden/unreachable as internals change.


const session = new ProbeInspectorSession({
probes: [{
expr: 'exitDuringProbe()',
target: { suffix: 'probe-exits-during-probe.js', line: 8 },
}],
});

const resume = Promise.withResolvers();
const evaluation = Promise.withResolvers();
session.client = {
callMethod: common.mustCall((method) => {
if (method === 'Debugger.resume') return resume.promise;
assert.strictEqual(method, 'Debugger.evaluateOnCallFrame');
return evaluation.promise;
}, 2),
};

async function testOverlappingCdpRequests() {
// A breakpoint pause can arrive before the response to the resume that
// triggered it. Reproduce that ordering without depending on CDP timing.
const resumeRequest = session.callCdp('Debugger.resume');
const evaluationRequest = session.callCdp(
'Debugger.evaluateOnCallFrame',
{},
{
index: 0,
location: {
url: 'file:///probe-exits-during-probe.js',
line: 8,
column: 1,
},
},
);
const evaluationInFlight = session.inFlight;

resume.resolve({});
await resumeRequest;

try {
assert.strictEqual(session.inFlight, evaluationInFlight);
} finally {
// Settle the synthetic evaluation so the test leaves no pending work.
session.finished = true;
evaluation.reject(new Error('synthetic inspector disconnect'));
await evaluationRequest.catch(common.mustCall());
}
}

testOverlappingCdpRequests().then(common.mustCall());
Loading