in pkg/accesslog/common/connection.go [588:620]
func (c *ConnectionManager) OnBuildConnectionLogFinished() {
// delete all connections which marked as deletable
// all deletable connection events been sent
deletableConnections := make(map[string]bool)
now := time.Now()
c.connections.IterCb(func(key string, v interface{}) {
con, ok := v.(*ConnectionInfo)
if !ok || con == nil {
return
}
// already mark as deletable or process not monitoring
shouldDelete := con.MarkDeletable || !c.ProcessIsMonitor(con.PID)
if !shouldDelete {
shouldDelete = !c.checkConnectionIsExist(con)
}
if shouldDelete && con.DeleteAfter == nil {
deleteAfterTime := now.Add(connectionDeleteDelayTime)
con.DeleteAfter = &deleteAfterTime
log.Debugf("detected the connection has mark as deletable, so add a delay timer, connection ID: %d, random ID: %d",
con.ConnectionID, con.RandomID)
}
if shouldDelete && now.After(*con.DeleteAfter) {
deletableConnections[key] = true
}
})
for key := range deletableConnections {
log.Debugf("deleting the connection in manager: %s", key)
c.connections.Remove(key)
}
}