From ea1f6517c1875622630ba3e709d024bcf7479dd2 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Thu, 6 Apr 2017 17:36:26 +0200 Subject: [PATCH] server: Fix RunPodSandbox error path When RunPodSandbox fails after calling s.addSandbox(sb), we're left with a sandbox in s.state.sandboxes while the sandbox is not created. We fix that by adding removeSandbox() to the deferred cleanup call Signed-off-by: Samuel Ortiz --- server/sandbox_run.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/server/sandbox_run.go b/server/sandbox_run.go index 19ced459..e883a977 100644 --- a/server/sandbox_run.go +++ b/server/sandbox_run.go @@ -282,19 +282,20 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest hostname: hostname, } - s.addSandbox(sb) - if err = s.podIDIndex.Add(id); err != nil { - return nil, err - } - defer func() { if err != nil { + s.removeSandbox(id) if err2 := s.podIDIndex.Delete(id); err2 != nil { logrus.Warnf("couldn't delete pod id %s from idIndex", id) } } }() + s.addSandbox(sb) + if err = s.podIDIndex.Add(id); err != nil { + return nil, err + } + for k, v := range annotations { g.AddAnnotation(k, v) }