This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-go.git


The following commit(s) were added to refs/heads/main by this push:
     new 4a28909  Resolve panic when root span finish (#187)
4a28909 is described below

commit 4a28909d5c943e8e1d67f0557da4e5761af28b62
Author: mrproliu <741550...@qq.com>
AuthorDate: Tue Jun 18 11:23:54 2024 +0000

    Resolve panic when root span finish (#187)
---
 CHANGES.md                   | 4 ++++
 plugins/core/span_tracing.go | 3 +++
 plugins/core/tracing/api.go  | 6 +++++-
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/CHANGES.md b/CHANGES.md
index 012339f..457182c 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -6,6 +6,7 @@ Release Notes.
 ------------------
 #### Features
 * Add support trace ignore.
+* Update the error message if the peer address is empty when creating exit 
span.
 
 #### Plugins
 * Support [Pulsar](https://github.com/apache/pulsar-client-go) MQ.
@@ -13,6 +14,9 @@ Release Notes.
 * Support http headers collection for Gin
 * Support higher versions of grpc.
 
+### Bug Fixes
+* Fix panic error when root span finished.
+
 #### Chore
 * Enhance the observability of makefile execution
 
diff --git a/plugins/core/span_tracing.go b/plugins/core/span_tracing.go
index 2871e37..978756a 100644
--- a/plugins/core/span_tracing.go
+++ b/plugins/core/span_tracing.go
@@ -256,6 +256,9 @@ func (rs *RootSegmentSpan) AsyncFinish() {
 
 func (rs *RootSegmentSpan) end0() {
        go func() {
+               defer func() {
+                       _ = recover()
+               }()
                rs.doneCh <- atomic.SwapInt32(rs.SegmentContext.refNum, -1)
        }()
 }
diff --git a/plugins/core/tracing/api.go b/plugins/core/tracing/api.go
index 5e409e8..55692a3 100644
--- a/plugins/core/tracing/api.go
+++ b/plugins/core/tracing/api.go
@@ -23,6 +23,7 @@ import (
 
 var (
        errParameter = operator.NewError("parameter are nil")
+       errPeerEmpty = operator.NewError("peer is empty")
 )
 
 // CreateEntrySpan creates a new entry span.
@@ -68,9 +69,12 @@ func CreateLocalSpan(operationName string, opts 
...SpanOption) (s Span, err erro
 // injector is the injector to inject the context into the carrier.
 // opts is the options to create the span.
 func CreateExitSpan(operationName, peer string, injector Injector, opts 
...SpanOption) (s Span, err error) {
-       if operationName == "" || peer == "" || injector == nil {
+       if operationName == "" || injector == nil {
                return nil, errParameter
        }
+       if peer == "" {
+               return nil, errPeerEmpty
+       }
        op := operator.GetOperator()
        if op == nil {
                return &NoopSpan{}, nil

Reply via email to