Skip to content

Commit

Permalink
Merge pull request #164 from coroot/handling_out_of_order
Browse files Browse the repository at this point in the history
close existing connection with same PID:FD when creating a new one
  • Loading branch information
def authored Dec 27, 2024
2 parents 1dbf538 + 09c1209 commit f49ea14
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
10 changes: 9 additions & 1 deletion containers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,12 @@ func (c *Container) onConnectionOpen(pid uint32, fd uint64, src, dst, actualDst
Timestamp: timestamp,
}
c.activeConnections[ConnectionKey{src: src, dst: dst}] = connection
c.connectionsByPidFd[PidFd{Pid: pid, Fd: fd}] = connection
k := PidFd{Pid: pid, Fd: fd}
prev := c.connectionsByPidFd[k]
if prev != nil {
prev.Closed = time.Now()
}
c.connectionsByPidFd[k] = connection
}
c.lastConnectionAttempts[key.Destination()] = time.Now()
}
Expand All @@ -569,6 +574,9 @@ func (c *Container) onConnectionClose(e ebpftracer.Event) {
conn := c.connectionsByPidFd[PidFd{Pid: e.Pid, Fd: e.Fd}]
c.lock.Unlock()
if conn != nil {
if conn.Timestamp != 0 && conn.Timestamp != e.Timestamp {
return
}
if conn.Closed.IsZero() {
if e.TrafficStats != nil {
c.lock.Lock()
Expand Down
20 changes: 10 additions & 10 deletions ebpftracer/ebpf.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ebpftracer/ebpf/tcp/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ int inet_sock_set_state(void *ctx)
timestamp = conn->timestamp;
type = EVENT_TYPE_CONNECTION_OPEN;
} else if (args.newstate == BPF_TCP_CLOSE) {
bpf_map_delete_elem(&connection_id_by_socket, &args.skaddr);
bpf_map_delete_elem(&active_connections, cid);
type = EVENT_TYPE_CONNECTION_ERROR;
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/containerd/cgroups v1.0.4
github.com/containerd/containerd v1.6.26
github.com/coreos/go-systemd/v22 v22.5.0
github.com/coroot/logparser v1.1.6
github.com/coroot/logparser v1.1.7
github.com/docker/docker v25.0.3+incompatible
github.com/florianl/go-conntrack v0.3.0
github.com/go-kit/log v0.2.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfc
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/coroot/dotnetdiag v1.2.2 h1:PVP/By8o+xhPjfVolJYcjHLbFQInM7pkaD6/otPLc8Q=
github.com/coroot/dotnetdiag v1.2.2/go.mod h1:veXCMlFzm1yNl7wwJb/ZLxO4WbzhDBoy1VG1XtkH2ls=
github.com/coroot/logparser v1.1.6 h1:iMZ7CfKfbSKDD+LayGnd14s9M6/T25/+GKosKYIMoCk=
github.com/coroot/logparser v1.1.6/go.mod h1:YfYxn9FYBm5GYHHUB4zI22irFAWVDe2bcbOWDHKSmEo=
github.com/coroot/logparser v1.1.7 h1:YdWD/4WhgXDwAyaZVzRnucCZC3Lkae9a5oy5g8wxmFg=
github.com/coroot/logparser v1.1.7/go.mod h1:YfYxn9FYBm5GYHHUB4zI22irFAWVDe2bcbOWDHKSmEo=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand Down

0 comments on commit f49ea14

Please sign in to comment.