From 0f2a0705309bb5ae57e1314a408a174d9d8c0217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 8 Oct 2020 19:49:42 +0200 Subject: [PATCH 1/4] runtime_vm: Fix updateContainerStatus() logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabiano Fidêncio --- internal/oci/runtime_vm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/oci/runtime_vm.go b/internal/oci/runtime_vm.go index b4b024d6d36..6e7577dc1ef 100644 --- a/internal/oci/runtime_vm.go +++ b/internal/oci/runtime_vm.go @@ -629,7 +629,7 @@ func (r *runtimeVM) updateContainerStatus(c *Container) error { ID: c.ID(), }) if err != nil { - if errors.Is(err, ttrpc.ErrClosed) { + if !errors.Is(err, ttrpc.ErrClosed) { return errdefs.FromGRPC(err) } return errdefs.ErrNotFound From 85f341c32c431648947087f93cd743f07b170f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Wed, 14 Oct 2020 02:00:49 +0200 Subject: [PATCH 2/4] runtime_vm: Don't let wait() return ttrpc.ErrClosed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Passing ttrpc.ErrClosed to errdefs.FromGRPC() will result in an "ttrpc: closed: unknown" error, which we can't match in any possible way. Knowing that let's, instead, return errdefs.ErrNotFound, as already done in updateContainerStatus() so we can properly match the error when it occurs. Signed-off-by: Fabiano Fidêncio --- internal/oci/runtime_vm.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/oci/runtime_vm.go b/internal/oci/runtime_vm.go index 6e7577dc1ef..401179a1e73 100644 --- a/internal/oci/runtime_vm.go +++ b/internal/oci/runtime_vm.go @@ -814,7 +814,10 @@ func (r *runtimeVM) wait(ctx context.Context, ctrID, execID string) (int32, erro ExecID: execID, }) if err != nil { - return -1, errdefs.FromGRPC(err) + if !errors.Is(err, ttrpc.ErrClosed) { + return -1, errdefs.FromGRPC(err) + } + return -1, errdefs.ErrNotFound } return int32(resp.ExitStatus), nil From 802b4e4fe270736b07177f8146256c97ad81dc20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Wed, 14 Oct 2020 02:22:03 +0200 Subject: [PATCH 3/4] runtime_vm: StopContainers() should not fail when the VM is shutdown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the goroutine used to monitor whether the container was terminated or not, we should not fail in case the VM was shutdown, as this is expected to happen and will cause a ttrpc.ErrClosed. runtime's wait() function, however, will returns errdefs.ErrNotFound when a ttrpc.ErrCloses happens in order to avoid returning "ttrpc: closed: unknown" (see previous commit) and that's the reason we just check for errdefs.ErrNotFound and do not error out in that case. Signed-off-by: Fabiano Fidêncio --- internal/oci/runtime_vm.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/oci/runtime_vm.go b/internal/oci/runtime_vm.go index 401179a1e73..70647bd85d7 100644 --- a/internal/oci/runtime_vm.go +++ b/internal/oci/runtime_vm.go @@ -509,7 +509,10 @@ func (r *runtimeVM) StopContainer(ctx context.Context, c *Container, timeout int stopCh := make(chan error) go func() { - if _, err := r.wait(ctx, c.ID(), ""); err != nil { + // errdefs.ErrNotFound actually comes from a closed connection, which is expected + // when stoping the container, with the agent and the VM going off. In such case. + // let's just ignore the error. + if _, err := r.wait(ctx, c.ID(), ""); err != nil && !errors.Is(err, errdefs.ErrNotFound) { stopCh <- errdefs.FromGRPC(err) } From 5f4774efc095e55a3d7cda4feb9735e4d25e08ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Wed, 14 Oct 2020 02:33:26 +0200 Subject: [PATCH 4/4] runtime_vm: Ignore ttrpc.ErrClosed when removing a container MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the VM is down when removing the container, ttrpc.ErrClosed would be returned and we'd return this error up in the chain. However, if the VM is down, so is the container and we could simply ignore the error reported, as already done in a few other parts of our code. Signed-off-by: Fabiano Fidêncio --- internal/oci/runtime_vm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/oci/runtime_vm.go b/internal/oci/runtime_vm.go index 70647bd85d7..1d10e29ba14 100644 --- a/internal/oci/runtime_vm.go +++ b/internal/oci/runtime_vm.go @@ -843,7 +843,7 @@ func (r *runtimeVM) remove(ctx context.Context, ctrID, execID string) error { if _, err := r.task.Delete(ctx, &task.DeleteRequest{ ID: ctrID, ExecID: execID, - }); err != nil { + }); err != nil && !errors.Is(err, ttrpc.ErrClosed) { return errdefs.FromGRPC(err) }