Skip to content

Commit e99c24c

Browse files
committed
fix races
1 parent 8dcbc96 commit e99c24c

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

pkg/network/sender/event_consumer_linux.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,21 @@ func (d *directSenderConsumer) HandleEvent(ev any) {
132132
}
133133
p.Cwd = cwd
134134
}
135-
if p.EventType == model.ForkEventType && p.PPid > 0 {
136-
if parent, ok := d.processes[p.PPid]; ok && parent != nil {
137-
p.Cmdline = parent.Cmdline
138-
}
139-
}
140135
d.process(p)
136+
d.proxyFilter.process(p)
137+
d.extractor.process(p)
141138
}
142139

143140
func (d *directSenderConsumer) process(p *process) {
144141
d.mtx.Lock()
145142
defer d.mtx.Unlock()
146143

144+
if p.EventType == model.ForkEventType && p.PPid > 0 {
145+
if parent, ok := d.processes[p.PPid]; ok && parent != nil {
146+
p.Cmdline = parent.Cmdline
147+
}
148+
}
149+
147150
if _, seen := d.processes[p.Pid]; seen {
148151
if p.EventType == model.ExitEventType {
149152
// mark process as dead so it will be removed after next set of connections are collected
@@ -154,8 +157,6 @@ func (d *directSenderConsumer) process(p *process) {
154157
if p.EventType == model.ExecEventType || p.EventType == model.ForkEventType {
155158
d.processes[p.Pid] = p
156159
}
157-
d.proxyFilter.process(p)
158-
d.extractor.process(p)
159160
eventConsumerTelemetry.processCount.Set(float64(len(d.processes)))
160161
}
161162

pkg/network/sender/tags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func (d *directSender) getContainersForExplicitTagging(currentConnections *netwo
9999
}
100100

101101
func (d *directSender) addContainerTags(c *model.Connection, containerIDForPID map[int32]string, containersForTagging map[string]types.EntityID, tagsEncoder model.TagEncoder) {
102+
c.LocalContainerTagsIndex = -1
102103
if c.Laddr.ContainerId == "" {
103104
return
104105
}

pkg/process/metadata/parser/service.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"runtime"
1212
"slices"
1313
"strings"
14+
"sync"
1415
"unicode"
1516

1617
"github.com/Masterminds/semver/v3"
@@ -64,6 +65,8 @@ type ServiceExtractor struct {
6465
useWindowsServiceName bool
6566
serviceByPID map[int32]*serviceMetadata
6667
scmReader *scmReader
68+
69+
mtx sync.RWMutex
6770
}
6871

6972
type serviceMetadata struct {
@@ -94,6 +97,8 @@ func (d *ServiceExtractor) Extract(processes map[int32]*procutil.Process) {
9497
if !d.enabled {
9598
return
9699
}
100+
d.mtx.Lock()
101+
defer d.mtx.Unlock()
97102

98103
serviceByPID := make(map[int32]*serviceMetadata)
99104

@@ -124,6 +129,8 @@ func (d *ServiceExtractor) ExtractSingle(proc *procutil.Process) {
124129
if !d.enabled {
125130
return
126131
}
132+
d.mtx.Lock()
133+
defer d.mtx.Unlock()
127134

128135
if meta, seen := d.serviceByPID[proc.Pid]; seen {
129136
// check the service metadata is for the same process
@@ -147,6 +154,8 @@ func (d *ServiceExtractor) Remove(pid int32) {
147154
if !d.enabled {
148155
return
149156
}
157+
d.mtx.Lock()
158+
defer d.mtx.Unlock()
150159

151160
delete(d.serviceByPID, pid)
152161
}
@@ -156,6 +165,8 @@ func (d *ServiceExtractor) GetServiceContext(pid int32) []string {
156165
if !d.enabled {
157166
return nil
158167
}
168+
d.mtx.RLock()
169+
defer d.mtx.RUnlock()
159170

160171
if runtime.GOOS == "windows" && d.useWindowsServiceName {
161172
tags, err := d.getWindowsServiceTags(pid)

0 commit comments

Comments
 (0)