In this case the time between the CONNECTION event and the second CLOSE event is ~140s which is less than 2mn + 30s (our expiry limit for TCP connections + our polling interval), that's why the connection was not considered expired by the userspace code.
The main issue is that the second close event has less stats than the connection event (without a connection close between the two), and there is only 2 close events for this daddr, dport couple in the eBPF logs (that relates to the 2 we have in the state dump).
(I also had a script running that took a dump of the eBPF map every 15 seconds and it didn't have any connection for this (daddr, dport) couple)
There is likely something wrong with how we deal with close events but I don't know what's the issue.
The goal of this PR is to at least fix the issue by clearing the old stats objects when we see a connection close event (except if the connection became active again). The issue could still appear if the interval between the CONNECTION and CLOSE event is smaller than our polling interval (30s).
It also fixes an other case where we could have underflows on closed connections becoming active again.
I took a dump of the state / added debug logs to the tracer and got:
In this case the time between the
CONNECTION
event and the secondCLOSE
event is ~140s which is less than 2mn + 30s (our expiry limit for TCP connections + our polling interval), that's why the connection was not considered expired by the userspace code.The main issue is that the second close event has less stats than the connection event (without a connection close between the two), and there is only 2 close events for this daddr, dport couple in the eBPF logs (that relates to the 2 we have in the state dump).
(I also had a script running that took a dump of the eBPF map every 15 seconds and it didn't have any connection for this (daddr, dport) couple)
There is likely something wrong with how we deal with close events but I don't know what's the issue.
I thought it was coming from close events we would drop here https://github.com/DataDog/datadog-process-agent/blob/master/ebpf/c/tracer-ebpf.c#L557 but I added a debug log there and it was not showing up so it does not seem to be the issue.
The goal of this PR is to at least fix the issue by clearing the old stats objects when we see a connection close event (except if the connection became active again). The issue could still appear if the interval between the CONNECTION and CLOSE event is smaller than our polling interval (30s).
It also fixes an other case where we could have underflows on closed connections becoming active again.