Remove old dns queries from DB
This commit is contained in:
@@ -41,18 +41,14 @@ func cleanConnections() (activePIDs map[int]struct{}) {
|
|||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
deleteOlderThan := time.Now().Add(-deleteConnsAfterEndedThreshold).Unix()
|
deleteOlderThan := time.Now().Add(-deleteConnsAfterEndedThreshold).Unix()
|
||||||
|
|
||||||
|
// network connections
|
||||||
connsLock.Lock()
|
connsLock.Lock()
|
||||||
defer connsLock.Unlock()
|
|
||||||
|
|
||||||
for key, conn := range conns {
|
for key, conn := range conns {
|
||||||
// get conn.Ended
|
|
||||||
conn.Lock()
|
conn.Lock()
|
||||||
ended := conn.Ended
|
|
||||||
conn.Unlock()
|
|
||||||
|
|
||||||
// delete inactive connections
|
// delete inactive connections
|
||||||
switch {
|
switch {
|
||||||
case ended == 0:
|
case conn.Ended == 0:
|
||||||
// Step 1: check if still active
|
// Step 1: check if still active
|
||||||
_, ok := activeIDs[key]
|
_, ok := activeIDs[key]
|
||||||
if ok {
|
if ok {
|
||||||
@@ -60,19 +56,34 @@ func cleanConnections() (activePIDs map[int]struct{}) {
|
|||||||
} else {
|
} else {
|
||||||
// Step 2: mark end
|
// Step 2: mark end
|
||||||
activePIDs[conn.process.Pid] = struct{}{}
|
activePIDs[conn.process.Pid] = struct{}{}
|
||||||
conn.Lock()
|
|
||||||
conn.Ended = now
|
conn.Ended = now
|
||||||
conn.Unlock()
|
|
||||||
// "save"
|
// "save"
|
||||||
dbController.PushUpdate(conn)
|
dbController.PushUpdate(conn)
|
||||||
}
|
}
|
||||||
case ended < deleteOlderThan:
|
case conn.Ended < deleteOlderThan:
|
||||||
// Step 3: delete
|
// Step 3: delete
|
||||||
log.Tracef("network.clean: deleted %s (ended at %s)", conn.DatabaseKey(), time.Unix(conn.Ended, 0))
|
log.Tracef("network.clean: deleted %s (ended at %s)", conn.DatabaseKey(), time.Unix(conn.Ended, 0))
|
||||||
conn.delete()
|
conn.delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conn.Unlock()
|
||||||
}
|
}
|
||||||
|
connsLock.Unlock()
|
||||||
|
|
||||||
|
// dns requests
|
||||||
|
dnsConnsLock.Lock()
|
||||||
|
for _, conn := range dnsConns {
|
||||||
|
conn.Lock()
|
||||||
|
|
||||||
|
// delete old dns connections
|
||||||
|
if conn.Ended < deleteOlderThan {
|
||||||
|
log.Tracef("network.clean: deleted %s (ended at %s)", conn.DatabaseKey(), time.Unix(conn.Ended, 0))
|
||||||
|
conn.delete()
|
||||||
|
}
|
||||||
|
|
||||||
|
conn.Unlock()
|
||||||
|
}
|
||||||
|
dnsConnsLock.Unlock()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user