cleanup container state if the reader tomb dies by itself (#1470)

This commit is contained in:
blotus 2022-04-22 10:52:44 +02:00 committed by GitHub
parent 242706a475
commit 8909fbdb22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View file

@ -507,6 +507,15 @@ func (d *DockerSource) TailDocker(container *ContainerConfig, outChan chan types
linesRead.With(prometheus.Labels{"source": container.Name}).Inc()
outChan <- evt
d.logger.Debugf("Sent line to parsing: %+v", evt.Line.Raw)
case <-readerTomb.Dying():
//This case is to handle temporarly losing the connection to the docker socket
//The only known case currently is when using docker-socket-proxy (and maybe a docker daemon restart)
d.logger.Debugf("readerTomb dying for container %s, removing it from runningContainerState", container.Name)
delete(d.runningContainerState, container.ID)
//Also reset the Since to avoid re-reading logs
d.Config.Since = time.Now().UTC().Format(time.RFC3339)
d.containerLogsOptions.Since = d.Config.Since
return nil
}
}
}

View file

@ -183,7 +183,7 @@ container_name_regexp:
ticker.Reset(1 * time.Second)
case <-ticker.C:
log.Infof("no more line to read")
readerTomb.Kill(nil)
streamTomb.Kill(nil)
return nil
}
}