From d1006fdfbc3c3065c4eb9dc79525b340eff0f801 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Tue, 4 Apr 2017 17:22:34 +0200 Subject: [PATCH] server: Add new sandboxes to the sandbox hash table first We want new sandboxes to be added to the sandbox hash table before adding their ID to the pod Index registrar, in order to avoid potential Update() races. Signed-off-by: Samuel Ortiz --- server/sandbox_run.go | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/server/sandbox_run.go b/server/sandbox_run.go index 410365f5..415eafd0 100644 --- a/server/sandbox_run.go +++ b/server/sandbox_run.go @@ -91,18 +91,6 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest } }() - if err = s.podIDIndex.Add(id); err != nil { - return nil, err - } - - defer func() { - if err != nil { - if err2 := s.podIDIndex.Delete(id); err2 != nil { - logrus.Warnf("couldn't delete pod id %s from idIndex", id) - } - } - }() - podContainer, err := s.storage.CreatePodSandbox(s.imageContext, name, id, s.config.PauseImage, "", @@ -278,6 +266,17 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest } s.addSandbox(sb) + if err = s.podIDIndex.Add(id); err != nil { + return nil, err + } + + defer func() { + if err != nil { + if err2 := s.podIDIndex.Delete(id); err2 != nil { + logrus.Warnf("couldn't delete pod id %s from idIndex", id) + } + } + }() for k, v := range annotations { g.AddAnnotation(k, v)