@@ -48,6 +48,8 @@ type CheckpointerOptions = {
48
48
chaosMonkey ?: ChaosMonkey ;
49
49
} ;
50
50
51
+ class CheckpointAbortError extends Error { }
52
+
51
53
async function getFileSize ( filePath : string ) : Promise < number > {
52
54
try {
53
55
const stats = await fs . stat ( filePath ) ;
@@ -400,6 +402,14 @@ export class Checkpointer {
400
402
const controller = new AbortController ( ) ;
401
403
this . #abortControllers. set ( runId , controller ) ;
402
404
405
+ const assertNotAborted = ( abortMessage ?: string ) => {
406
+ if ( controller . signal . aborted ) {
407
+ throw new CheckpointAbortError ( abortMessage ) ;
408
+ }
409
+
410
+ this . #logger. debug ( "Not aborted" , { abortMessage } ) ;
411
+ } ;
412
+
403
413
const $$ = $ ( { signal : controller . signal } ) ;
404
414
405
415
const shortCode = nanoid ( 8 ) ;
@@ -423,6 +433,7 @@ export class Checkpointer {
423
433
} ;
424
434
425
435
try {
436
+ assertNotAborted ( "chaosMonkey.call" ) ;
426
437
await this . chaosMonkey . call ( { $ : $$ } ) ;
427
438
428
439
this . #logger. log ( "Checkpointing:" , { options } ) ;
@@ -479,6 +490,7 @@ export class Checkpointer {
479
490
return { success : false , reason : "SKIP_RETRYING" } ;
480
491
}
481
492
493
+ assertNotAborted ( "cmd: crictl ps" ) ;
482
494
const containerId = this . #logger. debug (
483
495
// @ts -expect-error
484
496
await $ `crictl ps`
@@ -501,6 +513,7 @@ export class Checkpointer {
501
513
}
502
514
503
515
// Create checkpoint
516
+ assertNotAborted ( "cmd: crictl checkpoint" ) ;
504
517
this . #logger. debug ( await $$ `crictl checkpoint --export=${ exportLocation } ${ containerId } ` ) ;
505
518
const postCheckpoint = performance . now ( ) ;
506
519
@@ -509,20 +522,25 @@ export class Checkpointer {
509
522
this . #logger. log ( "checkpoint archive created" , { size, options } ) ;
510
523
511
524
// Create image from checkpoint
525
+ assertNotAborted ( "cmd: buildah from scratch" ) ;
512
526
const container = this . #logger. debug ( await $$ `buildah from scratch` ) ;
513
527
const postFrom = performance . now ( ) ;
514
528
529
+ assertNotAborted ( "cmd: buildah add" ) ;
515
530
this . #logger. debug ( await $$ `buildah add ${ container } ${ exportLocation } /` ) ;
516
531
const postAdd = performance . now ( ) ;
517
532
533
+ assertNotAborted ( "cmd: buildah config" ) ;
518
534
this . #logger. debug (
519
535
await $$ `buildah config --annotation=io.kubernetes.cri-o.annotations.checkpoint.name=counter ${ container } `
520
536
) ;
521
537
const postConfig = performance . now ( ) ;
522
538
539
+ assertNotAborted ( "cmd: buildah commit" ) ;
523
540
this . #logger. debug ( await $$ `buildah commit ${ container } ${ imageRef } ` ) ;
524
541
const postCommit = performance . now ( ) ;
525
542
543
+ assertNotAborted ( "cmd: buildah rm" ) ;
526
544
this . #logger. debug ( await $$ `buildah rm ${ container } ` ) ;
527
545
const postRm = performance . now ( ) ;
528
546
@@ -534,6 +552,7 @@ export class Checkpointer {
534
552
}
535
553
536
554
// Push checkpoint image
555
+ assertNotAborted ( "cmd: buildah push" ) ;
537
556
this . #logger. debug (
538
557
await $$ `buildah push --tls-verify=${ String ( this . registryTlsVerify ) } ${ imageRef } `
539
558
) ;
@@ -559,9 +578,15 @@ export class Checkpointer {
559
578
} ,
560
579
} ;
561
580
} catch ( error ) {
581
+ if ( error instanceof CheckpointAbortError ) {
582
+ this . #logger. error ( "Checkpoint canceled: CheckpointAbortError" , { options, error } ) ;
583
+
584
+ return { success : false , reason : "CANCELED" } ;
585
+ }
586
+
562
587
if ( isExecaChildProcess ( error ) ) {
563
588
if ( error . isCanceled ) {
564
- this . #logger. error ( "Checkpoint canceled" , { options, error } ) ;
589
+ this . #logger. error ( "Checkpoint canceled: ExecaChildProcess " , { options, error } ) ;
565
590
566
591
return { success : false , reason : "CANCELED" } ;
567
592
}
0 commit comments