Skip to content

Commit

Permalink
shim cleanup on exit
Browse files Browse the repository at this point in the history
Fixed bug introduced by earlier PR where graceful shim shutdown
prevents containerd from deleting the sandbox bundle since
the shim is still using it and containerd errors, because another
process is using that directory and the files within it.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
  • Loading branch information
helsaawy committed Mar 7, 2022
1 parent f50f975 commit ec8aa8c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions cmd/containerd-shim-runhcs-v1/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,24 @@ var serveCommand = cli.Command{
// Shouldn't need to os.Exit without clean up (ie, deferred `.Close()`s)
return nil
}
// currently the ttrpc shutdown is the only clean up to wait on

// containerd waits for the ttrpc server to close, then deletes the sanbox
// bundle.
// However, this (serve) command is started with the bundle path as the cwd
// and panic.log (created within the sandbox bundle) as the stderr. This
// prevents containerd from deleting the bundle if this process is still
// alive.
// Change the directory to the parent and close stderr (panic.log) to
// allow bundle deletion to succeed.
if err = os.Chdir(".."); err != nil {
logrus.WithError(err).Warn("could not change working directory to bundle directory parent ")
}
os.Stderr.Close()

sctx, cancel := context.WithTimeout(context.Background(), gracefulShutdownTimeout)
defer cancel()
err = s.Shutdown(sctx)
// ignore the error, since we closed stderr (and stdout)
s.Shutdown(sctx) // nolint: errcheck
}

return err
Expand Down

0 comments on commit ec8aa8c

Please sign in to comment.