@@ -602,7 +602,7 @@ func (c *Container) WaitForExit(ctx context.Context, pollInterval time.Duration)
602602 defer c .lock .Unlock ()
603603
604604 if err := c .syncContainer (); err != nil {
605- if errors .Is (err , define .ErrNoSuchCtr ) {
605+ if errors .Is (err , define .ErrNoSuchCtr ) || errors . Is ( err , define . ErrCtrRemoved ) {
606606 // if the container is not valid at this point as it was deleted,
607607 // check if the exit code was recorded in the db.
608608 exitCode , err := c .runtime .state .GetContainerExitCode (id )
@@ -649,7 +649,7 @@ func (c *Container) WaitForExit(ctx context.Context, pollInterval time.Duration)
649649
650650 // we locked again so we must sync the state
651651 if err := c .syncContainer (); err != nil {
652- if errors .Is (err , define .ErrNoSuchCtr ) {
652+ if errors .Is (err , define .ErrNoSuchCtr ) || errors . Is ( err , define . ErrCtrRemoved ) {
653653 // if the container is not valid at this point as it was deleted,
654654 // check if the exit code was recorded in the db.
655655 exitCode , err := c .runtime .state .GetContainerExitCode (id )
@@ -771,6 +771,12 @@ func (c *Container) WaitForConditionWithInterval(ctx context.Context, waitTimeou
771771 // This allows callers to actually wait for the ctr to be removed.
772772 if wantedStates [define .ContainerStateRemoving ] &&
773773 (errors .Is (err , define .ErrNoSuchCtr ) || errors .Is (err , define .ErrCtrRemoved )) {
774+ // check if the exit code was recorded in the db to return it
775+ exitCode , err := c .runtime .state .GetContainerExitCode (c .ID ())
776+ if err == nil {
777+ trySend (exitCode , nil )
778+ }
779+
774780 trySend (- 1 , nil )
775781 return
776782 }
0 commit comments