From 4578cc93d1eb5524a63b0f919465a1a7495934d9 Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Tue, 27 Sep 2016 10:40:08 +0200 Subject: [PATCH] server: fix panic when listing sandboxes Signed-off-by: Antonio Murdaca --- server/sandbox.go | 6 ++++++ server/server.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/server/sandbox.go b/server/sandbox.go index f24dd5b2..796e2c30 100644 --- a/server/sandbox.go +++ b/server/sandbox.go @@ -313,6 +313,7 @@ func (s *Server) RemovePodSandbox(ctx context.Context, req *pb.RemovePodSandboxR } s.releasePodName(sb.name) + s.removeSandbox(sandboxID) return &pb.RemovePodSandboxResponse{}, nil } @@ -380,6 +381,11 @@ func (s *Server) ListPodSandbox(context.Context, *pb.ListPodSandboxRequest) (*pb for _, sb := range s.state.sandboxes { podInfraContainerName := sb.name + "-infra" podInfraContainer := sb.getContainer(podInfraContainerName) + if podInfraContainer == nil { + // this can't really happen, but if it does because of a bug + // it's better not to panic + continue + } if err := s.runtime.UpdateStatus(podInfraContainer); err != nil { return nil, err } diff --git a/server/server.go b/server/server.go index 6876ac01..68bc895b 100644 --- a/server/server.go +++ b/server/server.go @@ -179,6 +179,12 @@ func (s *Server) hasSandbox(id string) bool { return ok } +func (s *Server) removeSandbox(id string) { + s.stateLock.Lock() + delete(s.state.sandboxes, id) + s.stateLock.Unlock() +} + func (s *Server) addContainer(c *oci.Container) { s.stateLock.Lock() sandbox := s.state.sandboxes[c.Sandbox()]