@@ -120,10 +120,18 @@ export class RunExecution {
120
120
}
121
121
122
122
if ( exitExecution ) {
123
- this . shutdown ( "kill" ) ;
123
+ this . shutdownExecution ( "kill" ) ;
124
124
}
125
125
}
126
126
127
+ public async shutdown ( ) {
128
+ if ( this . taskRunProcess ) {
129
+ await this . taskRunProcessProvider . handleProcessAbort ( this . taskRunProcess ) ;
130
+ }
131
+
132
+ this . shutdownExecution ( "shutdown" ) ;
133
+ }
134
+
127
135
/**
128
136
* Prepares the execution with task run environment variables.
129
137
* This should be called before executing, typically after a successful run to prepare for the next one.
@@ -232,7 +240,6 @@ export class RunExecution {
232
240
if ( this . currentAttemptNumber && this . currentAttemptNumber !== run . attemptNumber ) {
233
241
this . sendDebugLog ( "error: attempt number mismatch" , snapshotMetadata ) ;
234
242
// This is a rogue execution, a new one will already have been created elsewhere
235
- // TODO: keep this one, kill the process even if it's a keep-alive one
236
243
await this . exitTaskRunProcessWithoutFailingRun ( {
237
244
flush : false ,
238
245
reason : "attempt number mismatch" ,
@@ -250,7 +257,6 @@ export class RunExecution {
250
257
if ( deprecated ) {
251
258
this . sendDebugLog ( "run execution is deprecated" , { incomingSnapshot : snapshot } ) ;
252
259
253
- // TODO: keep this one, kill the process even if it's a keep-alive one
254
260
await this . exitTaskRunProcessWithoutFailingRun ( {
255
261
flush : false ,
256
262
reason : "deprecated execution" ,
@@ -469,7 +475,7 @@ export class RunExecution {
469
475
if ( startError ) {
470
476
this . sendDebugLog ( "failed to start attempt" , { error : startError . message } ) ;
471
477
472
- this . shutdown ( "failed to start attempt" ) ;
478
+ this . shutdownExecution ( "failed to start attempt" ) ;
473
479
return ;
474
480
}
475
481
@@ -480,12 +486,12 @@ export class RunExecution {
480
486
if ( executeError ) {
481
487
this . sendDebugLog ( "failed to execute run" , { error : executeError . message } ) ;
482
488
483
- this . shutdown ( "failed to execute run" ) ;
489
+ this . shutdownExecution ( "failed to execute run" ) ;
484
490
return ;
485
491
}
486
492
487
493
// This is here for safety, but it
488
- this . shutdown ( "execute call finished" ) ;
494
+ this . shutdownExecution ( "execute call finished" ) ;
489
495
}
490
496
491
497
private async executeRunWrapper ( {
@@ -786,7 +792,7 @@ export class RunExecution {
786
792
if ( startError ) {
787
793
this . sendDebugLog ( "failed to start attempt for retry" , { error : startError . message } ) ;
788
794
789
- this . shutdown ( "retryImmediately: failed to start attempt" ) ;
795
+ this . shutdownExecution ( "retryImmediately: failed to start attempt" ) ;
790
796
return ;
791
797
}
792
798
@@ -797,7 +803,7 @@ export class RunExecution {
797
803
if ( executeError ) {
798
804
this . sendDebugLog ( "failed to execute run for retry" , { error : executeError . message } ) ;
799
805
800
- this . shutdown ( "retryImmediately: failed to execute run" ) ;
806
+ this . shutdownExecution ( "retryImmediately: failed to execute run" ) ;
801
807
return ;
802
808
}
803
809
}
@@ -841,7 +847,7 @@ export class RunExecution {
841
847
await this . taskRunProcessProvider . suspendProcess ( flush , this . taskRunProcess ) ;
842
848
843
849
// No services should be left running after this line - let's make sure of it
844
- this . shutdown ( `exitTaskRunProcessWithoutFailingRun: ${ reason } ` ) ;
850
+ this . shutdownExecution ( `exitTaskRunProcessWithoutFailingRun: ${ reason } ` ) ;
845
851
}
846
852
847
853
/**
@@ -1012,10 +1018,10 @@ export class RunExecution {
1012
1018
}
1013
1019
1014
1020
this . executionAbortController . abort ( ) ;
1015
- this . shutdown ( "abortExecution" ) ;
1021
+ this . shutdownExecution ( "abortExecution" ) ;
1016
1022
}
1017
1023
1018
- private shutdown ( reason : string ) {
1024
+ private shutdownExecution ( reason : string ) {
1019
1025
if ( this . isShuttingDown ) {
1020
1026
this . sendDebugLog ( `[shutdown] ${ reason } (already shutting down)` , {
1021
1027
firstShutdownReason : this . shutdownReason ,
0 commit comments