server: fix panic when listing sandboxes

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2016-09-27 10:40:08 +02:00
parent 56f2b34def
commit 4578cc93d1
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
2 changed files with 12 additions and 0 deletions

View file

@ -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
}

View file

@ -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()]