From aac425c761960af457964ad6da2f8491634d74e2 Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Tue, 16 May 2017 08:53:19 -0700 Subject: [PATCH] Terminate linux shim on create failure Since an error is returned via the RPC clients will assume (rightly so) that a call to the Delete() RPC is not necessary. Signed-off-by: Kenfe-Mickael Laventure --- linux/runtime.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/linux/runtime.go b/linux/runtime.go index a41f492aa..3849bf387 100644 --- a/linux/runtime.go +++ b/linux/runtime.go @@ -97,7 +97,13 @@ func (r *Runtime) Create(ctx context.Context, id string, opts plugin.CreateOpts) os.RemoveAll(path) return nil, err } - if err := r.handleEvents(s); err != nil { + // Exit the shim on error + defer func() { + if err != nil { + s.Exit(context.Background(), &shim.ExitRequest{}) + } + }() + if err = r.handleEvents(s); err != nil { os.RemoveAll(path) return nil, err } @@ -120,13 +126,13 @@ func (r *Runtime) Create(ctx context.Context, id string, opts plugin.CreateOpts) if len(sopts.Rootfs) == 0 { return nil, fmt.Errorf("no rootfs was specified for id %s", id) } - if _, err := s.Create(ctx, sopts); err != nil { + if _, err = s.Create(ctx, sopts); err != nil { os.RemoveAll(path) return nil, err } c := newContainer(id, s) // after the container is create add it to the monitor - if err := r.monitor.Monitor(c); err != nil { + if err = r.monitor.Monitor(c); err != nil { return nil, err } return c, nil