Skip to content

Commit

Permalink
Call RefDec in exit only if not cached processes
Browse files Browse the repository at this point in the history
Now eventcache handles the RefDec() calls both for process and parent
if the exit event goes into the eventcache.

So calling RefDec() before checking if we need to cache the event
may results in double calls to RefDec().

Signed-off-by: Anastasios Papagiannis <[email protected]>
  • Loading branch information
tpapagian committed Aug 12, 2022
1 parent 7e7b2b4 commit 03bdc1c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions pkg/grpc/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ func GetProcessExit(event *MsgExitEventUnix) *tetragon.ProcessExit {

process, parent := process.GetParentProcessInternal(event.ProcessKey.Pid, event.ProcessKey.Ktime)
if process != nil {
process.RefDec()
tetragonProcess = process.UnsafeGetProcess()
} else {
tetragonProcess = &tetragon.Process{
Expand All @@ -175,7 +174,6 @@ func GetProcessExit(event *MsgExitEventUnix) *tetragon.ProcessExit {
}
}
if parent != nil {
parent.RefDec()
tetragonParent = parent.GetProcessCopy()
}

Expand All @@ -195,7 +193,11 @@ func GetProcessExit(event *MsgExitEventUnix) *tetragon.ProcessExit {
ec.Add(process, tetragonEvent, event.ProcessKey.Ktime, event)
return nil
}
if parent != nil {
parent.RefDec()
}
if process != nil {
process.RefDec()
tetragonEvent.Process = process.GetProcessCopy()
}
return tetragonEvent
Expand Down
2 changes: 1 addition & 1 deletion pkg/grpc/exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ func TestGrpcParentRefcntInOrder(t *testing.T) {
assert.Equal(t, currentExitEv.Process.Pid.Value, currentPid)
assert.Equal(t, currentExitEv.Process.Refcnt, uint32(0))
assert.Equal(t, currentExitEv.Parent.Pid.Value, parentPid)
assert.Equal(t, currentExitEv.Parent.Refcnt, uint32(1))
assert.Equal(t, currentExitEv.Parent.Refcnt, uint32(2))

// 4th event: exit from parent
// 1. should match pid of parent
Expand Down

0 comments on commit 03bdc1c

Please sign in to comment.