浏览代码

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

blotus 3 年之前
父节点
当前提交
8909fbdb22
共有 2 个文件被更改,包括 10 次插入1 次删除
  1. 9 0
      pkg/acquisition/modules/docker/docker.go
  2. 1 1
      pkg/acquisition/modules/docker/docker_test.go

+ 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()
 			linesRead.With(prometheus.Labels{"source": container.Name}).Inc()
 			outChan <- evt
 			outChan <- evt
 			d.logger.Debugf("Sent line to parsing: %+v", evt.Line.Raw)
 			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)
 					ticker.Reset(1 * time.Second)
 				case <-ticker.C:
 				case <-ticker.C:
 					log.Infof("no more line to read")
 					log.Infof("no more line to read")
-					readerTomb.Kill(nil)
+					streamTomb.Kill(nil)
 					return nil
 					return nil
 				}
 				}
 			}
 			}