mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
docker connector: refresh() delete container only if it not found but keep on failures
If inspect() call was failed due to connection problems then container will be removed anyway as like ot wasn't found. This is probably almost never happens in real life but still some missed logic bug
This commit is contained in:
parent
df0d8b7892
commit
65e9c6dff6
@ -160,9 +160,12 @@ func ipsFormat(networks map[string]api.ContainerNetwork) string {
|
||||
}
|
||||
|
||||
func (cm *Docker) refresh(c *container.Container) {
|
||||
insp := cm.inspect(c.Id)
|
||||
insp, found, failed := cm.inspect(c.Id)
|
||||
if failed {
|
||||
return
|
||||
}
|
||||
// remove container if no longer exists
|
||||
if insp == nil {
|
||||
if !found {
|
||||
cm.delByID(c.Id)
|
||||
return
|
||||
}
|
||||
@ -178,14 +181,17 @@ func (cm *Docker) refresh(c *container.Container) {
|
||||
c.SetState(insp.State.Status)
|
||||
}
|
||||
|
||||
func (cm *Docker) inspect(id string) *api.Container {
|
||||
func (cm *Docker) inspect(id string) (insp *api.Container, found bool, failed bool) {
|
||||
c, err := cm.client.InspectContainer(id)
|
||||
if err != nil {
|
||||
if _, ok := err.(*api.NoSuchContainer); !ok {
|
||||
log.Errorf("%s (%T)", err.Error(), err)
|
||||
if _, notFound := err.(*api.NoSuchContainer); notFound {
|
||||
return c, false, false
|
||||
}
|
||||
// other error e.g. connection failed
|
||||
log.Errorf("%s (%T)", err.Error(), err)
|
||||
return c, false, true
|
||||
}
|
||||
return c
|
||||
return c, true, false
|
||||
}
|
||||
|
||||
// Mark all container IDs for refresh
|
||||
|
Loading…
Reference in New Issue
Block a user