Skip to content

Commit daba2c2

Browse files
committed
test: defer pause to avoid pause forever
Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com>
1 parent b59def5 commit daba2c2

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

lib/internal/debugger/inspect_probe.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ class ProbeInspectorSession {
474474
this.inFlight = null;
475475
// Most recently completed probe, used for `error.probe` when a non-evaluate CDP call rejects.
476476
this.lastProbeIndex = null;
477+
this.deferredStartupPause = null;
478+
this.handledPauseAfterStart = false;
477479
const { promise, resolve } = PromiseWithResolvers();
478480
this.completionPromise = promise;
479481
this.resolveCompletion = resolve;
@@ -624,10 +626,17 @@ class ProbeInspectorSession {
624626

625627
async handlePaused(params) {
626628
if (this.finished) { return; }
627-
// Ignore pauses that arrive before breakpoint setup is complete. Once
629+
// Defer pauses that arrive before breakpoint setup is complete. Once
628630
// startup is marked complete, `Runtime.runIfWaitingForDebugger` may surface
629-
// the initial --inspect-brk pause, which the normal resume path handles.
630-
if (!this.started) { return; }
631+
// the initial --inspect-brk pause, which the normal resume path handles. If
632+
// it was already surfaced while binding breakpoints, replay it after startup
633+
// so the target is not left paused forever.
634+
if (!this.started) {
635+
this.deferredStartupPause = params;
636+
return;
637+
}
638+
639+
this.handledPauseAfterStart = true;
631640

632641
const hitBreakpoints = params.hitBreakpoints;
633642
if (hitBreakpoints === undefined || hitBreakpoints.length === 0) {
@@ -676,6 +685,16 @@ class ProbeInspectorSession {
676685
await this.resume();
677686
}
678687

688+
async handleDeferredStartupPause() {
689+
if (this.deferredStartupPause === null || this.handledPauseAfterStart) {
690+
return;
691+
}
692+
693+
const params = this.deferredStartupPause;
694+
this.deferredStartupPause = null;
695+
await this.handlePaused(params);
696+
}
697+
679698
async evaluateProbe(callFrameId, probeIndex, location) {
680699
if (this.finished) { return; }
681700
const probe = this.probes[probeIndex];
@@ -998,6 +1017,7 @@ class ProbeInspectorSession {
9981017
this.started = true;
9991018
this.startTimeout();
10001019
await this.callCdp('Runtime.runIfWaitingForDebugger');
1020+
await this.handleDeferredStartupPause();
10011021
} catch (err) {
10021022
if (err !== kInspectorFailedSentinel) { throw err; }
10031023
}

test/parallel/test-debugger-probe-startup-pause.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Flags: --expose-internals
2-
// This tests that probe mode ignores pauses until startup has finished binding
2+
// This tests that probe mode defers pauses until startup has finished binding
33
// breakpoints.
44
'use strict';
55

@@ -25,7 +25,7 @@ async function testStartupPauseHandling() {
2525
assert.deepStrictEqual(cdpCalls, []);
2626

2727
session.started = true;
28-
await session.handlePaused({});
28+
await session.handleDeferredStartupPause();
2929
assert.deepStrictEqual(cdpCalls, ['Debugger.resume']);
3030
}
3131

0 commit comments

Comments
 (0)