@@ -48,6 +48,8 @@ type CheckpointerOptions = {
4848  chaosMonkey ?: ChaosMonkey ; 
4949} ; 
5050
51+ class  CheckpointAbortError  extends  Error  { } 
52+ 
5153async  function  getFileSize ( filePath : string ) : Promise < number >  { 
5254  try  { 
5355    const  stats  =  await  fs . stat ( filePath ) ; 
@@ -400,6 +402,14 @@ export class Checkpointer {
400402    const  controller  =  new  AbortController ( ) ; 
401403    this . #abortControllers. set ( runId ,  controller ) ; 
402404
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+ 
403413    const  $$  =  $ ( {  signal : controller . signal  } ) ; 
404414
405415    const  shortCode  =  nanoid ( 8 ) ; 
@@ -423,6 +433,7 @@ export class Checkpointer {
423433    } ; 
424434
425435    try  { 
436+       assertNotAborted ( "chaosMonkey.call" ) ; 
426437      await  this . chaosMonkey . call ( {  $ : $$  } ) ; 
427438
428439      this . #logger. log ( "Checkpointing:" ,  {  options } ) ; 
@@ -479,6 +490,7 @@ export class Checkpointer {
479490        return  {  success : false ,  reason : "SKIP_RETRYING"  } ; 
480491      } 
481492
493+       assertNotAborted ( "cmd: crictl ps" ) ; 
482494      const  containerId  =  this . #logger. debug ( 
483495        // @ts -expect-error 
484496        await  $ `crictl ps` 
@@ -501,6 +513,7 @@ export class Checkpointer {
501513      } 
502514
503515      // Create checkpoint 
516+       assertNotAborted ( "cmd: crictl checkpoint" ) ; 
504517      this . #logger. debug ( await  $$ `crictl checkpoint --export=${ exportLocation }   ${ containerId }  ` ) ; 
505518      const  postCheckpoint  =  performance . now ( ) ; 
506519
@@ -509,20 +522,25 @@ export class Checkpointer {
509522      this . #logger. log ( "checkpoint archive created" ,  {  size,  options } ) ; 
510523
511524      // Create image from checkpoint 
525+       assertNotAborted ( "cmd: buildah from scratch" ) ; 
512526      const  container  =  this . #logger. debug ( await  $$ `buildah from scratch` ) ; 
513527      const  postFrom  =  performance . now ( ) ; 
514528
529+       assertNotAborted ( "cmd: buildah add" ) ; 
515530      this . #logger. debug ( await  $$ `buildah add ${ container }   ${ exportLocation }   /` ) ; 
516531      const  postAdd  =  performance . now ( ) ; 
517532
533+       assertNotAborted ( "cmd: buildah config" ) ; 
518534      this . #logger. debug ( 
519535        await  $$ `buildah config --annotation=io.kubernetes.cri-o.annotations.checkpoint.name=counter ${ container }  ` 
520536      ) ; 
521537      const  postConfig  =  performance . now ( ) ; 
522538
539+       assertNotAborted ( "cmd: buildah commit" ) ; 
523540      this . #logger. debug ( await  $$ `buildah commit ${ container }   ${ imageRef }  ` ) ; 
524541      const  postCommit  =  performance . now ( ) ; 
525542
543+       assertNotAborted ( "cmd: buildah rm" ) ; 
526544      this . #logger. debug ( await  $$ `buildah rm ${ container }  ` ) ; 
527545      const  postRm  =  performance . now ( ) ; 
528546
@@ -534,6 +552,7 @@ export class Checkpointer {
534552      } 
535553
536554      // Push checkpoint image 
555+       assertNotAborted ( "cmd: buildah push" ) ; 
537556      this . #logger. debug ( 
538557        await  $$ `buildah push --tls-verify=${ String ( this . registryTlsVerify ) }   ${ imageRef }  ` 
539558      ) ; 
@@ -559,9 +578,15 @@ export class Checkpointer {
559578        } , 
560579      } ; 
561580    }  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+ 
562587      if  ( isExecaChildProcess ( error ) )  { 
563588        if  ( error . isCanceled )  { 
564-           this . #logger. error ( "Checkpoint canceled" ,  {  options,  error } ) ; 
589+           this . #logger. error ( "Checkpoint canceled: ExecaChildProcess " ,  {  options,  error } ) ; 
565590
566591          return  {  success : false ,  reason : "CANCELED"  } ; 
567592        } 
0 commit comments