Skip to content

Commit

Permalink
daemon: fix GetContainer() returning (nil, nil)
Browse files Browse the repository at this point in the history
GetContainer() would return (nil, nil) when looking up a container
if the container was inserted into the containersReplica ViewDB but not
the containers Store at the time of the lookup. Callers which reasonably
assume that the returned err == nil implies returned container != nil
would dereference a nil pointer and panic. Change GetContainer() so that
it always returns a container or an error.

Signed-off-by: Cory Snider <csnider@mirantis.com>
(cherry picked from commit 00157a4)
Signed-off-by: Cory Snider <csnider@mirantis.com>
  • Loading branch information
corhere committed Dec 13, 2022
1 parent abcb4c5 commit 42bffae
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion daemon/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,18 @@ func (daemon *Daemon) GetContainer(prefixOrName string) (*container.Container, e
}
return nil, errdefs.System(indexError)
}
return daemon.containers.Get(containerID), nil
ctr := daemon.containers.Get(containerID)
if ctr == nil {
// Updates to the daemon.containersReplica ViewDB are not atomic
// or consistent w.r.t. the live daemon.containers Store so
// while reaching this code path may be indicative of a bug,
// it is not _necessarily_ the case.
logrus.WithField("prefixOrName", prefixOrName).
WithField("id", containerID).
Debugf("daemon.GetContainer: container is known to daemon.containersReplica but not daemon.containers")
return nil, containerNotFound(prefixOrName)
}
return ctr, nil
}

// checkContainer make sure the specified container validates the specified conditions
Expand Down

0 comments on commit 42bffae

Please sign in to comment.