Skip to content

Commit 6aa30c1

Browse files
committed
[netpath] Fix panic in npCollector cause by forwader.SendEventPlatformEventBlocking() call
todo
1 parent c8cfa50 commit 6aa30c1

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

comp/networkpath/npcollector/npcollectorimpl/npcollector.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"errors"
1313
"fmt"
1414
"net"
15+
"sync"
1516
"time"
1617

1718
model "github.com/DataDog/agent-payload/v5/process"
@@ -62,6 +63,7 @@ type npCollectorImpl struct {
6263
workers int
6364
stopChan chan struct{}
6465
flushLoopDone chan struct{}
66+
workersDone chan struct{}
6567
runDone chan struct{}
6668
flushInterval time.Duration
6769

@@ -122,6 +124,7 @@ func newNpCollectorImpl(epForwarder eventplatform.Forwarder, collectorConfigs *c
122124
stopChan: make(chan struct{}),
123125
runDone: make(chan struct{}),
124126
flushLoopDone: make(chan struct{}),
127+
workersDone: make(chan struct{}),
125128

126129
runTraceroute: runTraceroute,
127130
statsdClient: statsd,
@@ -274,7 +277,7 @@ func (s *npCollectorImpl) start() error {
274277

275278
go s.listenPathtests()
276279
go s.flushLoop()
277-
s.startWorkers()
280+
go s.startWorkers()
278281

279282
return nil
280283
}
@@ -286,6 +289,7 @@ func (s *npCollectorImpl) stop() {
286289
}
287290
close(s.stopChan)
288291
<-s.flushLoopDone
292+
<-s.workersDone
289293
<-s.runDone
290294
s.running = false
291295
}
@@ -496,13 +500,24 @@ func (s *npCollectorImpl) getReverseDNSResult(ipAddr string, results map[string]
496500

497501
func (s *npCollectorImpl) startWorkers() {
498502
s.logger.Debugf("Starting workers (%d)", s.workers)
503+
504+
// TODO: TEST ME
505+
// TODO: TEST ME
506+
// TODO: TEST ME
507+
var wg sync.WaitGroup
499508
for w := 0; w < s.workers; w++ {
509+
wg.Add(1)
500510
s.logger.Debugf("Starting worker #%d", w)
501-
go s.startWorker(w)
511+
go func() {
512+
defer wg.Done()
513+
s.runWorker(w)
514+
}()
502515
}
516+
wg.Wait()
517+
s.workersDone <- struct{}{}
503518
}
504519

505-
func (s *npCollectorImpl) startWorker(workerID int) {
520+
func (s *npCollectorImpl) runWorker(workerID int) {
506521
for {
507522
select {
508523
case <-s.stopChan:

comp/networkpath/npcollector/npcollectorimpl/npcollector_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ func Test_npCollectorImpl_stopWorker(t *testing.T) {
548548

549549
stopped := make(chan bool, 1)
550550
go func() {
551-
npCollector.startWorker(42)
551+
npCollector.runWorker(42)
552552
stopped <- true
553553
}()
554554
close(npCollector.stopChan)

0 commit comments

Comments
 (0)