From 69bb746a1de7bdc9238efadaa507ab40fb9c6315 Mon Sep 17 00:00:00 2001 From: ansoda Date: Fri, 8 Mar 2024 18:28:23 +0800 Subject: [PATCH] fix: StopAgent panics when trace agent disabled (#3981) Co-authored-by: ansoda --- core/trace/agent.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/trace/agent.go b/core/trace/agent.go index 2a2e8c37..59e0e23e 100644 --- a/core/trace/agent.go +++ b/core/trace/agent.go @@ -59,7 +59,13 @@ func StartAgent(c Config) { // StopAgent shuts down the span processors in the order they were registered. func StopAgent() { - _ = tp.Shutdown(context.Background()) + lock.Lock() + defer lock.Unlock() + + if tp != nil { + _ = tp.Shutdown(context.Background()) + tp = nil + } } func createExporter(c Config) (sdktrace.SpanExporter, error) {