File tree 2 files changed +18
-10
lines changed
2 files changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -922,7 +922,7 @@ func (c *Container) gc(now time.Time) {
922
922
listens := map [netaddr.IPPort ]string {}
923
923
seenNamespaces := map [string ]bool {}
924
924
for _ , p := range c .processes {
925
- if seenNamespaces [p .NetNsId ] {
925
+ if seenNamespaces [p .NetNsId () ] {
926
926
continue
927
927
}
928
928
sockets , err := proc .GetSockets (p .Pid )
@@ -937,7 +937,7 @@ func (c *Container) gc(now time.Time) {
937
937
establishedDst [s .DAddr ] = struct {}{}
938
938
}
939
939
}
940
- seenNamespaces [p .NetNsId ] = true
940
+ seenNamespaces [p .NetNsId () ] = true
941
941
}
942
942
943
943
for ns := range c .ipsByNs {
Original file line number Diff line number Diff line change @@ -15,7 +15,8 @@ import (
15
15
type Process struct {
16
16
Pid uint32
17
17
StartedAt time.Time
18
- NetNsId string
18
+
19
+ netNsId string
19
20
20
21
ctx context.Context
21
22
cancelFunc context.CancelFunc
@@ -28,19 +29,26 @@ type Process struct {
28
29
}
29
30
30
31
func NewProcess (pid uint32 , stats * taskstats.Stats ) * Process {
31
- ns , err := proc .GetNetNs (pid )
32
- if err != nil {
33
- return nil
34
- }
35
- defer ns .Close ()
36
- p := & Process {Pid : pid , StartedAt : stats .BeginTime , NetNsId : ns .UniqueId ()}
32
+ p := & Process {Pid : pid , StartedAt : stats .BeginTime }
37
33
p .ctx , p .cancelFunc = context .WithCancel (context .Background ())
38
34
go p .instrument ()
39
35
return p
40
36
}
41
37
38
+ func (p * Process ) NetNsId () string {
39
+ if p .netNsId == "" {
40
+ ns , err := proc .GetNetNs (p .Pid )
41
+ if err != nil {
42
+ return ""
43
+ }
44
+ p .netNsId = ns .UniqueId ()
45
+ _ = ns .Close ()
46
+ }
47
+ return p .netNsId
48
+ }
49
+
42
50
func (p * Process ) isHostNs () bool {
43
- return p .NetNsId == hostNetNsId
51
+ return p .NetNsId () == hostNetNsId
44
52
}
45
53
46
54
func (p * Process ) instrument () {
You can’t perform that action at this time.
0 commit comments