Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
runtime-v2: Make sure Shutdown() only shuts the server down
Browse files Browse the repository at this point in the history
Because the runtime v2 runs as a RPC server, the caller will at some
point use the Shutdown() API to shut down the server. Because this
will cause the server to exit, the caller cannot expect any valid
answer when calling this. That's why we cannot afford stopping and
deleting the sandbox from this function.

Instead, we move sandbox.Stop() and sandbox.Delete() to a more
appropriate API, the Delete() one.

Fixes #1150

Signed-off-by: Sebastien Boeuf <[email protected]>
  • Loading branch information
Sebastien Boeuf committed Jan 18, 2019
1 parent d7b02c5 commit 5329a71
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions containerd-shim-v2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,22 @@ func (s *service) Delete(ctx context.Context, r *taskAPI.DeleteRequest) (*taskAP
return nil, err
}

// Take care of the use case where it is a sandbox.
// Right after the container representing the sandbox has
// been deleted, let's make sure we stop and delete the
// sandbox.
if c.cType.IsSandbox() {
if err = s.sandbox.Stop(); err != nil {
logrus.WithField("sandbox", s.sandbox.ID()).Error("failed to stop sandbox")
return nil, err
}

if err = s.sandbox.Delete(); err != nil {
logrus.WithField("sandbox", s.sandbox.ID()).Error("failed to delete sandbox")
return nil, err
}
}

return &taskAPI.DeleteResponse{
ExitStatus: c.exit,
ExitedAt: c.time,
Expand Down Expand Up @@ -654,26 +670,17 @@ func (s *service) Connect(ctx context.Context, r *taskAPI.ConnectRequest) (*task

func (s *service) Shutdown(ctx context.Context, r *taskAPI.ShutdownRequest) (*ptypes.Empty, error) {
s.Lock()
defer s.Unlock()

if len(s.containers) != 0 {
s.Unlock()
return empty, nil
}
s.Unlock()

defer os.Exit(0)

err := s.sandbox.Stop()
if err != nil {
logrus.WithField("sandbox", s.sandbox.ID()).Error("failed to stop sandbox")
return empty, err
}

err = s.sandbox.Delete()
if err != nil {
logrus.WithField("sandbox", s.sandbox.ID()).Error("failed to delete sandbox")
}
os.Exit(0)

return empty, err
// This will never be called, but this is only there to make sure the
// program can compile.
return empty, nil
}

func (s *service) Stats(ctx context.Context, r *taskAPI.StatsRequest) (*taskAPI.StatsResponse, error) {
Expand Down

0 comments on commit 5329a71

Please sign in to comment.