You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2025/05/13 11:20:44 UTC

(dubbo-go) branch develop updated: fix: 修复 err != nil 判断位置错误导致可能 panic 的 bug (#2874)

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

alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/develop by this push:
     new 69e8ae1fa fix: 修复 err != nil 判断位置错误导致可能 panic 的 bug (#2874)
69e8ae1fa is described below

commit 69e8ae1fa0088cf0718ff50490c528612afa5ef4
Author: 陈钢阳 <ph...@gmail.com>
AuthorDate: Tue May 13 19:20:39 2025 +0800

    fix: 修复 err != nil 判断位置错误导致可能 panic 的 bug (#2874)
---
 remoting/getty/readwriter.go | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/remoting/getty/readwriter.go b/remoting/getty/readwriter.go
index 883f8a5b7..ddc66f6ea 100644
--- a/remoting/getty/readwriter.go
+++ b/remoting/getty/readwriter.go
@@ -66,30 +66,30 @@ func (p *RpcClientPackageHandler) Write(ss getty.Session, pkg any) ([]byte, erro
 	maxBufLength := clientConf.GettySessionParam.MaxMsgLen + impl.HEADER_LENGTH
 	if ok {
 		buf, err := (p.client.codec).EncodeRequest(req)
+		if err != nil {
+			logger.Warnf("binary.Write(req{%#v}) = err{%#v}", req, perrors.WithStack(err))
+			return nil, perrors.WithStack(err)
+		}
 		bufLength := buf.Len()
 		if bufLength > maxBufLength {
 			logger.Errorf("Data length %d too large, max payload %d", bufLength-impl.HEADER_LENGTH, clientConf.GettySessionParam.MaxMsgLen)
 			return nil, perrors.Errorf("Data length %d too large, max payload %d", bufLength-impl.HEADER_LENGTH, clientConf.GettySessionParam.MaxMsgLen)
 		}
-		if err != nil {
-			logger.Warnf("binary.Write(req{%#v}) = err{%#v}", req, perrors.WithStack(err))
-			return nil, perrors.WithStack(err)
-		}
 		return buf.Bytes(), nil
 	}
 
 	res, ok := pkg.(*remoting.Response)
 	if ok {
 		buf, err := (p.client.codec).EncodeResponse(res)
+		if err != nil {
+			logger.Warnf("binary.Write(res{%#v}) = err{%#v}", req, perrors.WithStack(err))
+			return nil, perrors.WithStack(err)
+		}
 		bufLength := buf.Len()
 		if bufLength > maxBufLength {
 			logger.Errorf("Data length %d too large, max payload %d", bufLength-impl.HEADER_LENGTH, clientConf.GettySessionParam.MaxMsgLen)
 			return nil, perrors.Errorf("Data length %d too large, max payload %d", bufLength-impl.HEADER_LENGTH, clientConf.GettySessionParam.MaxMsgLen)
 		}
-		if err != nil {
-			logger.Warnf("binary.Write(res{%#v}) = err{%#v}", req, perrors.WithStack(err))
-			return nil, perrors.WithStack(err)
-		}
 		return buf.Bytes(), nil
 	}