debugger: wait for target startup · nodejs/node@d69bed2 · GitHub
Skip to content

Commit d69bed2

Browse files
panvaArchkon
authored andcommitted
debugger: wait for target startup
The inspector can accept a connection before an --inspect-brk target enters its frontend wait. Runtime.runIfWaitingForDebugger can then be handled too early, allowing the target to subsequently block forever. Wait for NodeRuntime.waitingForDebugger before initializing and releasing launched targets. Race the handshake against disconnects and apply it to both interactive and probe startup. Refs: #64116 Assisted-by: codex:gpt-5.6-sol Co-authored-by: Archkon <180910180+Archkon@users.noreply.github.com> Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com> Signed-off-by: Filip Skokan <panva.ip@gmail.com> PR-URL: #65194 Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 5219e53 commit d69bed2

7 files changed

Lines changed: 629 additions & 3 deletions

lib/internal/debugger/inspect_helpers.js

Lines changed: 195 additions & 1 deletion

lib/internal/debugger/inspect_probe.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const InspectClient = require('internal/debugger/inspect_client');
3333
const {
3434
ensureTrailingNewline,
3535
launchChildProcess,
36+
waitForDebugger,
3637
} = require('internal/debugger/inspect_helpers');
3738

3839
const { ERR_DEBUGGER_STARTUP_ERROR } = require('internal/errors').codes;
@@ -1044,6 +1045,17 @@ class ProbeInspectorSession {
10441045
this.connected = true;
10451046

10461047
try {
1048+
try {
1049+
await waitForDebugger(
1050+
this.client,
1051+
(method) => this.callCdp(method),
1052+
);
1053+
} catch (err) {
1054+
// A close event may have completed the structured report while the
1055+
// readiness helper was rejecting its disconnect race.
1056+
if (this.finished) { throw kInspectorFailedSentinel; }
1057+
throw err;
1058+
}
10471059
await this.callCdp('Runtime.enable');
10481060
await this.callCdp('Debugger.enable');
10491061
await this.bindBreakpoints();

lib/internal/debugger/inspect_repl.js

Lines changed: 6 additions & 1 deletion

0 commit comments

Comments
 (0)