You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by yu...@apache.org on 2024/11/28 02:39:38 UTC

(rocketmq-client-go) branch master updated: Add stack info when consuming fail (#1164)

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

yuzhou pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-client-go.git


The following commit(s) were added to refs/heads/master by this push:
     new 8a0459a  Add stack info when consuming fail (#1164)
8a0459a is described below

commit 8a0459a849645d2074aada5fec5a04ea9f6f21f8
Author: tiger lee <ti...@apache.org>
AuthorDate: Thu Nov 28 10:39:32 2024 +0800

    Add stack info when consuming fail (#1164)
    
    * fix can't send batch message error
    
    * log stack info when consume fail
    
    ---------
    
    Co-authored-by: tiger lee <fr...@outlook.com>
    Co-authored-by: tigerweili <ti...@tencent.com>
---
 consumer/push_consumer.go        | 1 +
 internal/remote/remote_client.go | 4 +++-
 internal/utils/errors.go         | 6 ++++++
 rlog/log.go                      | 1 +
 4 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/consumer/push_consumer.go b/consumer/push_consumer.go
index 1a3d233..db6a37e 100644
--- a/consumer/push_consumer.go
+++ b/consumer/push_consumer.go
@@ -1113,6 +1113,7 @@ func (pc *pushConsumer) consumeMessageConcurrently(pq *processQueue, mq *primiti
 				if err := recover(); err != nil {
 					rlog.Error("consumeMessageConcurrently panic", map[string]interface{}{
 						rlog.LogKeyUnderlayError: err,
+						rlog.LogKeyStack:         utils.GetStackAsString(false),
 						rlog.LogKeyConsumerGroup: pc.consumerGroup,
 					})
 				}
diff --git a/internal/remote/remote_client.go b/internal/remote/remote_client.go
index eabfb75..55a2646 100644
--- a/internal/remote/remote_client.go
+++ b/internal/remote/remote_client.go
@@ -21,6 +21,7 @@ import (
 	"bytes"
 	"context"
 	"encoding/binary"
+	"github.com/apache/rocketmq-client-go/v2/internal/utils"
 	"io"
 	"net"
 	"sync"
@@ -286,7 +287,8 @@ func (c *remotingClient) createScanner(r io.Reader) *bufio.Scanner {
 		defer func() {
 			if err := recover(); err != nil {
 				rlog.Error("scanner split panic", map[string]interface{}{
-					"panic": err,
+					rlog.LogKeyUnderlayError: err,
+					rlog.LogKeyStack:         utils.GetStackAsString(false),
 				})
 			}
 		}()
diff --git a/internal/utils/errors.go b/internal/utils/errors.go
index 0887a37..b7c30c2 100644
--- a/internal/utils/errors.go
+++ b/internal/utils/errors.go
@@ -19,6 +19,7 @@ package utils
 
 import (
 	"github.com/apache/rocketmq-client-go/v2/rlog"
+	"runtime"
 )
 
 func CheckError(action string, err error) {
@@ -28,3 +29,8 @@ func CheckError(action string, err error) {
 		})
 	}
 }
+func GetStackAsString(all bool) string {
+	buf := make([]byte, 1<<10)
+	stackSize := runtime.Stack(buf, all)
+	return string(buf[:stackSize])
+}
diff --git a/rlog/log.go b/rlog/log.go
index 5c99e2d..253dd6b 100644
--- a/rlog/log.go
+++ b/rlog/log.go
@@ -44,6 +44,7 @@ const (
 	LogKeyQueueId              = "queueId"
 	LogKeyQueueOffset          = "queueOffset"
 	LogKeyMessages             = "messages"
+	LogKeyStack                = "stack"
 )
 
 type Logger interface {