Kaynağa Gözat

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

blotus 3 yıl önce
ebeveyn
işleme
8909fbdb22

+ 9 - 0
pkg/acquisition/modules/docker/docker.go

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

+ 1 - 1
pkg/acquisition/modules/docker/docker_test.go

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