Skip to content

Commit

Permalink
expire connection delay
Browse files Browse the repository at this point in the history
  • Loading branch information
jpinsonneau committed Mar 30, 2023
1 parent 04e1b0c commit f84abc4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
14 changes: 7 additions & 7 deletions pkg/pipeline/extract/conntrack/conntrack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1046,21 +1046,21 @@ func TestDetectEndConnection(t *testing.T) {
"5s: end connection",
startTime.Add(5 * time.Second),
[]config.GenericMap{flTCP2},
[]config.GenericMap{
newMockRecordEndConnAB(ipA, portA, ipB, portB, protocolTCP, 111, 222, 11, 22, 2).withHash(hashIdTCP).get(),
},
[]config.GenericMap(nil),
},
{
"10s: end connection duplicated",
startTime.Add(10 * time.Second),
"6s: end connection duplicated",
startTime.Add(6 * time.Second),
[]config.GenericMap{flTCP2Duplicated},
[]config.GenericMap(nil),
},
{
"21s: no end connection",
"15s: end connection without duplicated",
startTime.Add(21 * time.Second),
[]config.GenericMap{},
nil,
[]config.GenericMap{
newMockRecordEndConnAB(ipA, portA, ipB, portB, protocolTCP, 111, 222, 11, 22, 2).withHash(hashIdTCP).get(),
},
},
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/pipeline/extract/conntrack/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ func (cs *connectionStore) expireConnection(hashId uint64) {
}
groupIdx := cs.hashId2groupIdx[hashId]
mom := cs.groups[groupIdx].mom
// Set the expiry time to the zero value of Time
conn.setExpiryTime(time.Time{})
// Move to the front of the list
err := mom.MoveToFront(utils.Key(hashId), expiryOrder)
// Set the expiry time to half of EndConnectionTimeout
timeoutMs := cs.groups[groupIdx].scheduling.EndConnectionTimeout.Duration.Milliseconds()
conn.setExpiryTime(cs.now().Add(time.Duration(timeoutMs/2) * time.Millisecond))
// Move to the back of the list
err := mom.MoveToBack(utils.Key(hashId), expiryOrder)
if err != nil {
log.Panicf("BUG. Can't update connection expiry time for hash %x: %v", hashId, err)
return
Expand Down

0 comments on commit f84abc4

Please sign in to comment.