@@ -90,13 +90,17 @@ export class TaskRunProcessProvider {
9090 : "keep-alive disabled" ,
9191 } ) ;
9292
93+ const existingPersistentProcess = this . persistentProcess ;
94+
9395 // Clean up old persistent process if it exists
94- if ( this . persistentProcess ) {
95- await this . cleanupPersistentProcess ( ) ;
96+ if ( existingPersistentProcess ) {
97+ await this . cleanupProcess ( existingPersistentProcess ) ;
9698 }
9799
98- const newProcess = this . createTaskRunProcess ( opts ) ;
99- return newProcess ;
100+ this . persistentProcess = this . createTaskRunProcess ( opts ) ;
101+ this . executionCount = 0 ;
102+
103+ return this . persistentProcess ;
100104 }
101105
102106 /**
@@ -160,7 +164,9 @@ export class TaskRunProcessProvider {
160164 */
161165 cleanup ( ) : void {
162166 if ( this . persistentProcess ) {
163- this . cleanupPersistentProcess ( ) ;
167+ this . sendDebugLog ( "cleanup() called" ) ;
168+
169+ this . cleanupProcess ( this . persistentProcess ) ;
164170 }
165171 }
166172
@@ -227,14 +233,11 @@ export class TaskRunProcessProvider {
227233 return process . isPreparedForNextRun || process . isPreparedForNextAttempt ;
228234 }
229235
230- private async cleanupPersistentProcess ( ) : Promise < void > {
231- if ( this . persistentProcess ) {
232- this . sendDebugLog ( "Cleaning up persistent TaskRunProcess" ) ;
236+ private async cleanupProcess ( taskRunProcess : TaskRunProcess ) : Promise < void > {
237+ if ( taskRunProcess ) {
238+ this . sendDebugLog ( "Cleaning up TaskRunProcess" , { pid : taskRunProcess . pid } ) ;
233239
234- // Don't await this - let it cleanup in the background
235- await this . persistentProcess . kill ( "SIGKILL" ) . catch ( ( ) => { } ) ;
236- this . persistentProcess = null ;
237- this . executionCount = 0 ;
240+ await taskRunProcess . kill ( "SIGKILL" ) . catch ( ( ) => { } ) ;
238241 }
239242 }
240243
0 commit comments