Skip to content

Commit 011a574

Browse files
committed
retry app type detection during container initialization
1 parent 2c95818 commit 011a574

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

containers/process.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package containers
22

33
import (
44
"context"
5+
"os"
56
"time"
67

8+
"github.com/jpillora/backoff"
9+
710
"github.com/cilium/ebpf/link"
811
"github.com/coroot/coroot-node-agent/proc"
912
"github.com/mdlayher/taskstats"
@@ -32,7 +35,7 @@ func NewProcess(pid uint32, stats *taskstats.Stats) *Process {
3235
defer ns.Close()
3336
p := &Process{Pid: pid, StartedAt: stats.BeginTime, NetNsId: ns.UniqueId()}
3437
p.ctx, p.cancelFunc = context.WithCancel(context.Background())
35-
p.instrument()
38+
go p.instrument()
3639
return p
3740
}
3841

@@ -41,11 +44,26 @@ func (p *Process) isHostNs() bool {
4144
}
4245

4346
func (p *Process) instrument() {
44-
if dotNetAppName, err := dotNetApp(p.Pid); err == nil {
45-
if dotNetAppName != "" {
46-
p.dotNetMonitor = NewDotNetMonitor(p.ctx, p.Pid, dotNetAppName)
47+
b := backoff.Backoff{Factor: 2, Min: time.Second, Max: time.Minute}
48+
for {
49+
select {
50+
case <-p.ctx.Done():
51+
return
52+
default:
53+
dest, err := os.Readlink(proc.Path(p.Pid, "exe"))
54+
if err != nil {
55+
return
56+
}
57+
if dest != "/" {
58+
if dotNetAppName, err := dotNetApp(p.Pid); err == nil {
59+
if dotNetAppName != "" {
60+
p.dotNetMonitor = NewDotNetMonitor(p.ctx, p.Pid, dotNetAppName)
61+
}
62+
return
63+
}
64+
}
65+
time.Sleep(b.Duration())
4766
}
48-
return
4967
}
5068
}
5169

0 commit comments

Comments
 (0)