瀏覽代碼

prevent deletion of an active connection while removing outdated connection with same FD

Nikolay Sivko 2 年之前
父節點
當前提交
58edfcfdc6
共有 1 個文件被更改,包括 7 次插入2 次删除
  1. 7 2
      containers/container.go

+ 7 - 2
containers/container.go

@@ -901,14 +901,19 @@ func (c *Container) gc(now time.Time) {
 	c.revalidateListens(now, listens)
 	c.revalidateListens(now, listens)
 
 
 	for srcDst, conn := range c.connectionsActive {
 	for srcDst, conn := range c.connectionsActive {
+		pidFd := PidFd{Pid: conn.Pid, Fd: conn.Fd}
 		if _, ok := established[srcDst]; !ok {
 		if _, ok := established[srcDst]; !ok {
 			delete(c.connectionsActive, srcDst)
 			delete(c.connectionsActive, srcDst)
-			delete(c.connectionsByPidFd, PidFd{Pid: conn.Pid, Fd: conn.Fd})
+			if conn == c.connectionsByPidFd[pidFd] {
+				delete(c.connectionsByPidFd, pidFd)
+			}
 			continue
 			continue
 		}
 		}
 		if !conn.Closed.IsZero() && now.Sub(conn.Closed) > gcInterval {
 		if !conn.Closed.IsZero() && now.Sub(conn.Closed) > gcInterval {
 			delete(c.connectionsActive, srcDst)
 			delete(c.connectionsActive, srcDst)
-			delete(c.connectionsByPidFd, PidFd{Pid: conn.Pid, Fd: conn.Fd})
+			if conn == c.connectionsByPidFd[pidFd] {
+				delete(c.connectionsByPidFd, pidFd)
+			}
 		}
 		}
 	}
 	}
 	for dst, at := range c.connectLastAttempt {
 	for dst, at := range c.connectLastAttempt {