From 406526fc4f39697a1aea39c96b39e3bbb1453893 Mon Sep 17 00:00:00 2001 From: php-lsys <43031308+php-lsys@users.noreply.github.com> Date: Wed, 24 Apr 2024 11:03:27 +0800 Subject: [PATCH] When serializing SpanModel, if there is any external modification of TAGS, it will lead to panic, add RLock before calling Send to prevent this error. (#218) When serializing SpanModel, if there is any external modification of TAGS, it will lead to panic, add RLock before calling Send to prevent this error. issues:https://github.com/openzipkin/zipkin-go/issues/217 Co-authored-by: liushan --- span_implementation.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/span_implementation.go b/span_implementation.go index ab2f39b..5b9c692 100644 --- a/span_implementation.go +++ b/span_implementation.go @@ -80,7 +80,9 @@ func (s *spanImpl) Finish() { if atomic.CompareAndSwapInt32(&s.mustCollect, 1, 0) { s.Duration = time.Since(s.Timestamp) if s.flushOnFinish { + s.mtx.RLock() s.tracer.reporter.Send(s.SpanModel) + s.mtx.RUnlock() } } } @@ -89,13 +91,17 @@ func (s *spanImpl) FinishedWithDuration(d time.Duration) { if atomic.CompareAndSwapInt32(&s.mustCollect, 1, 0) { s.Duration = d if s.flushOnFinish { + s.mtx.RLock() s.tracer.reporter.Send(s.SpanModel) + s.mtx.RUnlock() } } } func (s *spanImpl) Flush() { if s.SpanModel.Debug || (s.SpanModel.Sampled != nil && *s.SpanModel.Sampled) { + s.mtx.RLock() s.tracer.reporter.Send(s.SpanModel) + s.mtx.RUnlock() } }