1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-07-15 01:04:25 +02:00

SDK: Multiple Unregister should not trigger multiple shutdown call (#176)

* SDK: Multiple Unregister should not trigger multiple shutdown call

* fix a data race: waitGroup.Add() should be outside of a goroutine
This commit is contained in:
Artem Kartasov
2019-10-09 13:31:29 +07:00
committed by rghetia
parent be8fb0b4e2
commit ffbef6a007
3 changed files with 12 additions and 9 deletions

View File

@ -38,7 +38,7 @@ type SpanProcessor interface {
Shutdown()
}
type spanProcessorMap map[SpanProcessor]struct{}
type spanProcessorMap map[SpanProcessor]*sync.Once
var (
mu sync.Mutex
@ -56,7 +56,7 @@ func RegisterSpanProcessor(e SpanProcessor) {
new[k] = v
}
}
new[e] = struct{}{}
new[e] = &sync.Once{}
spanProcessors.Store(new)
}
@ -71,7 +71,11 @@ func UnregisterSpanProcessor(s SpanProcessor) {
new[k] = v
}
}
if stopOnce, ok := new[s]; ok && stopOnce != nil {
stopOnce.Do(func() {
s.Shutdown()
})
}
delete(new, s)
spanProcessors.Store(new)
s.Shutdown()
}