Skip to content

Commit f66d43b

Browse files
authored
Merge pull request #144 from parca-dev/fix-npe
Fix NPE, can't return nil with no error from Attach
2 parents 1d3cd8f + b361674 commit f66d43b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

interpreter/oomwatcher/oomwatcher.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package oomwatcher // import "go.opentelemetry.io/ebpf-profiler/interpreter/oomw
55

66
import (
77
"fmt"
8+
"os"
89
"strings"
910

1011
"github.com/parca-dev/oomprof/oomprof"
@@ -77,6 +78,10 @@ func Loader(_ interpreter.EbpfHandler, info *interpreter.LoaderInfo) (interprete
7778
// Attach creates an observer instance for the given process.
7879
func (d *oomWatcherData) Attach(ebpf interpreter.EbpfHandler, pid libpf.PID,
7980
_ libpf.Address, _ remotememory.RemoteMemory) (interpreter.Instance, error) {
81+
if os.Getpid() == int(pid) {
82+
// Don't watch ourself, a parent process is required to report OOM's on the agent.
83+
return nil, oomprof.ErrSelfWatch
84+
}
8085
instance := &oomWatcherInstance{
8186
pid: pid,
8287
data: d,
@@ -86,9 +91,6 @@ func (d *oomWatcherData) Attach(ebpf interpreter.EbpfHandler, pid libpf.PID,
8691
if d.state != nil {
8792
logf("oom: watching PID %d", pid)
8893
if err := d.state.WatchPid(uint32(pid)); err != nil {
89-
if err == oomprof.ErrSelfWatch {
90-
return nil, nil
91-
}
9294
return nil, fmt.Errorf("failed to watch PID %d: %w", pid, err)
9395
}
9496
}

0 commit comments

Comments
 (0)