Skip to content

Commit 3ed213f

Browse files
authored
fix: not being able to debug child processes of commands that exit (#2206)
1 parent 41c8021 commit 3ed213f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/targets/node/nodeLauncherBase.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ export abstract class NodeLauncherBase<T extends AnyNodeConfiguration> implement
130130
*/
131131
private bootloaderFile = once(this.getBootloaderFile.bind(this));
132132

133+
/**
134+
* Map of all cached openers we've seen. It's possible for a command to run
135+
* and spawn another command and then exit. We want to make that command
136+
* debuggable so long as there is anyone in the tree to parent to, so we
137+
* can use this tree to look that up (where targets are deleted once exited).
138+
*/
139+
private seenOpeners = new Map</* opener ID */ string, { openedBy: string | undefined }>();
140+
133141
constructor(
134142
@inject(INodeBinaryProvider) private readonly pathProvider: INodeBinaryProvider,
135143
@inject(ILogger) protected readonly logger: ILogger,
@@ -391,6 +399,13 @@ export abstract class NodeLauncherBase<T extends AnyNodeConfiguration> implement
391399
targetInfo.processId = Number(targetInfo.targetId); // old bootloaders
392400
}
393401

402+
let livingOpenerId = targetInfo.openerId;
403+
while (
404+
livingOpenerId && !this.targets.get(livingOpenerId) && this.seenOpeners.has(livingOpenerId)
405+
) {
406+
livingOpenerId = this.seenOpeners.get(livingOpenerId)?.openedBy;
407+
}
408+
394409
const target = new NodeTarget(
395410
this.run.params,
396411
this.run.context.targetOrigin,
@@ -399,9 +414,10 @@ export abstract class NodeLauncherBase<T extends AnyNodeConfiguration> implement
399414
targetInfo,
400415
this.run.logger,
401416
this.createLifecycle(cdp, this.run, targetInfo),
402-
targetInfo.openerId ? this.targets.get(targetInfo.openerId) : undefined,
417+
livingOpenerId ? this.targets.get(livingOpenerId) : undefined,
403418
);
404419

420+
this.seenOpeners.set(targetInfo.targetId, { openedBy: targetInfo.openerId });
405421
this.listenToWorkerDomain(cdp, telemetryReporter, target);
406422
this.targets.add(targetInfo.targetId, target);
407423
target.onDisconnect(() => this.targets.remove(targetInfo.targetId));

0 commit comments

Comments
 (0)