Skip to content

Commit

Permalink
runtime_vm: Ignore ttrpc.ErrClosed when shutting the container down
Browse files Browse the repository at this point in the history
When shutting the container down, we're dealing with the following piece
of code on Kata side:
https://github.com/kata-containers/runtime/blob/master/containerd-shim-v2/service.go#L785
```
func (s *service) Shutdown(ctx context.Context, r *taskAPI.ShutdownRequest) (_ *ptypes.Empty, err error) {
	defer func() {
		err = toGRPC(err)
	}()

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

	s.cancel()

	os.Exit(0)

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

The code shown above will simply stop the service, closing the ttrpc
channel, raising then the "ErrClosed" error, which is returned by the
Shutdown.

Differently from containerd code, which simply igores the error, CRI-O
propagates the error, leaving a bunch of processes behind that will
never ever be closed.

Here's what containerd does:
https://github.com/containerd/containerd/blob/master/runtime/v2/shim.go#L194
```
        _, err := s.task.Shutdown(ctx, &task.ShutdownRequest{
                ID: s.ID(),
        })
        if err != nil && !errors.Is(err, ttrpc.ErrClosed) {
                return errdefs.FromGRPC(err)
        }
```

Knowing that, let's mimic what's been done by containerd and ignore the
error in this specific case.

Related: kata-containers/runtime#2719

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
  • Loading branch information
fidencio authored and openshift-cherrypick-robot committed Jul 17, 2020
1 parent 7c01831 commit 12a7846
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion internal/oci/runtime_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ func (r *runtimeVM) DeleteContainer(c *Container) error {
return err
}

if _, err := r.task.Shutdown(r.ctx, &task.ShutdownRequest{ID: c.ID()}); err != nil {
if _, err := r.task.Shutdown(r.ctx, &task.ShutdownRequest{ID: c.ID()}); err != nil && !errors.Is(err, ttrpc.ErrClosed) {
return err
}

Expand Down

0 comments on commit 12a7846

Please sign in to comment.