This is an automated email from the ASF dual-hosted git repository.
liuhan pushed a commit to branch fix-protocol-lost
in repository https://gitbox.apache.org/repos/asf/skywalking-rover.git
The following commit(s) were added to refs/heads/fix-protocol-lost by this push:
new 431bb8b added a delay time for delete connection
431bb8b is described below
commit 431bb8b917d9062cc3b9bd0e1b290f2877f926e0
Author: mrproliu <[email protected]>
AuthorDate: Wed Nov 13 11:02:38 2024 +0900
added a delay time for delete connection
---
pkg/accesslog/common/connection.go | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/pkg/accesslog/common/connection.go
b/pkg/accesslog/common/connection.go
index 3681f95..0caf2e7 100644
--- a/pkg/accesslog/common/connection.go
+++ b/pkg/accesslog/common/connection.go
@@ -54,6 +54,9 @@ const (
// clean the active connection in BPF interval
cleanActiveConnectionInterval = time.Second * 20
+
+ // in case the reading the data from BPF queue is disordered, so add a
delay time to delete the connection infomation
+ connectionDeleteDelayTime = time.Second * 20
)
type addressProcessType int
@@ -147,6 +150,7 @@ type ConnectionInfo struct {
MarkDeletable bool
PID uint32
Socket *ip.SocketPair
+ DeleteAfter *time.Time
}
func NewConnectionManager(config *Config, moduleMgr *module.Manager, bpfLoader
*bpf.Loader, filter MonitorFilter) *ConnectionManager {
@@ -620,6 +624,7 @@ func (c *ConnectionManager) OnBuildConnectionLogFinished() {
// delete all connections which marked as deletable
// all deletable connection events been sent
deletableConnections := make(map[string]bool, 0)
+ now := time.Now()
c.connections.IterCb(func(key string, v interface{}) {
con, ok := v.(*ConnectionInfo)
if !ok || con == nil {
@@ -628,7 +633,12 @@ func (c *ConnectionManager) OnBuildConnectionLogFinished()
{
// already mark as deletable or process not monitoring
shouldDelete := con.MarkDeletable ||
!c.ProcessIsMonitor(con.PID)
- if shouldDelete {
+ if con.DeleteAfter == nil {
+ deleteAfterTime := now.Add(connectionDeleteDelayTime)
+ con.DeleteAfter = &deleteAfterTime
+ }
+
+ if shouldDelete && now.After(*con.DeleteAfter) {
deletableConnections[key] = true
}
})