@@ -130,6 +130,14 @@ export abstract class NodeLauncherBase<T extends AnyNodeConfiguration> implement
130
130
*/
131
131
private bootloaderFile = once ( this . getBootloaderFile . bind ( this ) ) ;
132
132
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
+
133
141
constructor (
134
142
@inject ( INodeBinaryProvider ) private readonly pathProvider : INodeBinaryProvider ,
135
143
@inject ( ILogger ) protected readonly logger : ILogger ,
@@ -391,6 +399,13 @@ export abstract class NodeLauncherBase<T extends AnyNodeConfiguration> implement
391
399
targetInfo . processId = Number ( targetInfo . targetId ) ; // old bootloaders
392
400
}
393
401
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
+
394
409
const target = new NodeTarget (
395
410
this . run . params ,
396
411
this . run . context . targetOrigin ,
@@ -399,9 +414,10 @@ export abstract class NodeLauncherBase<T extends AnyNodeConfiguration> implement
399
414
targetInfo ,
400
415
this . run . logger ,
401
416
this . createLifecycle ( cdp , this . run , targetInfo ) ,
402
- targetInfo . openerId ? this . targets . get ( targetInfo . openerId ) : undefined ,
417
+ livingOpenerId ? this . targets . get ( livingOpenerId ) : undefined ,
403
418
) ;
404
419
420
+ this . seenOpeners . set ( targetInfo . targetId , { openedBy : targetInfo . openerId } ) ;
405
421
this . listenToWorkerDomain ( cdp , telemetryReporter , target ) ;
406
422
this . targets . add ( targetInfo . targetId , target ) ;
407
423
target . onDisconnect ( ( ) => this . targets . remove ( targetInfo . targetId ) ) ;
0 commit comments