diff --git a/oci/oci.go b/oci/oci.go index 3243e593..17f884be 100644 --- a/oci/oci.go +++ b/oci/oci.go @@ -17,6 +17,7 @@ import ( rspec "github.com/opencontainers/runtime-spec/specs-go" "github.com/sirupsen/logrus" "golang.org/x/sys/unix" + kwait "k8s.io/apimachinery/pkg/util/wait" ) const ( @@ -591,7 +592,22 @@ func (r *Runtime) UpdateStatus(c *Container) error { if c.state.Status == ContainerStateStopped { exitFilePath := filepath.Join(r.containerExitsDir, c.id) - fi, err := os.Stat(exitFilePath) + var fi os.FileInfo + err = kwait.ExponentialBackoff( + kwait.Backoff{ + Duration: 500 * time.Millisecond, + Factor: 1.2, + Steps: 6, + }, + func() (bool, error) { + var err error + fi, err = os.Stat(exitFilePath) + if err != nil { + // wait longer + return false, nil + } + return true, nil + }) if err != nil { logrus.Warnf("failed to find container exit file: %v", err) c.state.ExitCode = -1 diff --git a/server/container_status.go b/server/container_status.go index 0ca1b7f9..b4684c9c 100644 --- a/server/container_status.go +++ b/server/container_status.go @@ -48,7 +48,6 @@ func (s *Server) ContainerStatus(ctx context.Context, req *pb.ContainerStatusReq // If we defaulted to exit code -1 earlier then we attempt to // get the exit code from the exit file again. - // TODO: We could wait in UpdateStatus for exit file to show up. if cState.ExitCode == -1 { err := s.Runtime().UpdateStatus(c) if err != nil {