prevent race in telemetry worker cleanup (#2879)
This commit is contained in:
@@ -128,6 +128,12 @@ func (s *StatsWorker) Close() bool {
|
|||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *StatsWorker) Closed() bool {
|
||||||
|
s.lock.Lock()
|
||||||
|
defer s.lock.Unlock()
|
||||||
|
return !s.closedAt.IsZero()
|
||||||
|
}
|
||||||
|
|
||||||
func (s *StatsWorker) collectStats(
|
func (s *StatsWorker) collectStats(
|
||||||
ts *timestamppb.Timestamp,
|
ts *timestamppb.Timestamp,
|
||||||
streamType livekit.StreamType,
|
streamType livekit.StreamType,
|
||||||
|
|||||||
@@ -160,7 +160,9 @@ func (t *telemetryService) FlushStats() {
|
|||||||
if reap != nil {
|
if reap != nil {
|
||||||
t.workersMu.Lock()
|
t.workersMu.Lock()
|
||||||
for reap != nil {
|
for reap != nil {
|
||||||
delete(t.workers, reap.participantID)
|
if reap == t.workers[reap.participantID] {
|
||||||
|
delete(t.workers, reap.participantID)
|
||||||
|
}
|
||||||
reap = reap.next
|
reap = reap.next
|
||||||
}
|
}
|
||||||
t.workersMu.Unlock()
|
t.workersMu.Unlock()
|
||||||
@@ -195,7 +197,7 @@ func (t *telemetryService) getOrCreateWorker(
|
|||||||
t.workersMu.Lock()
|
t.workersMu.Lock()
|
||||||
defer t.workersMu.Unlock()
|
defer t.workersMu.Unlock()
|
||||||
|
|
||||||
if worker, ok := t.workers[participantID]; ok {
|
if worker, ok := t.workers[participantID]; ok && !worker.Closed() {
|
||||||
return worker, true
|
return worker, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user