eye-gu opened a new issue, #3296:
URL: https://github.com/apache/dubbo-go/issues/3296

   ### ✅ 验证清单
   
   - [x] 🔍 我已经搜索过 [现有 
Issues](https://github.com/apache/dubbo-go/issues),确信这不是重复问题
   
   ### 🚀 Go 版本
   
   1.25.6
   
   ### 📦 Dubbo-go 版本
   
   develop
   
   ### 🖥️ 服务端配置
   
   _No response_
   
   ### 💻 客户端配置
   
   _No response_
   
   ### 🌐 协议配置
   
   _No response_
   
   ### 📋 注册中心配置
   
   _No response_
   
   ### 💾 操作系统
   
   🍎 macOS
   
   ### 📝 Bug 描述
   
   
https://github.com/apache/dubbo-go/blob/28fc318c6667f820191bb6670aac27a4378d0712/protocol/jsonrpc/server.go#L156-L157
   
   err一定是nil
   
   ### 🔄 重现步骤
   
   向 jsonrpc 端口发送一个 Content-Type 为 text/plain 的请求,例如:
   
   curl --location '127.0.0.1:20002/GreetProvider' \
   --header 'Content-Type: text/plain' \
   --data 
'{"jsonrpc":"2.0","method":"SayHello","params":["hello","new","jsonrpc"],"id":1650901121}'
   
   ### ✅ 预期行为
   
   不panic,可以返回客户端不支持
   
   ### ❌ 实际行为
   
   2026-04-18 01:13:09  WARN    jsonrpc/server.go:83    
connection{local:127.0.0.1:20002, remote:127.0.0.1:49903} panic error:"invalid 
memory address or nil pointer dereference", debug stack:goroutine 168 [running]:
   runtime/debug.Stack()
        /usr/local/go/src/runtime/debug/stack.go:26 +0x74
   dubbo.apache.org/dubbo-go/v3/protocol/jsonrpc.(*Server).handlePkg.func1()
        
/Users/guzemin/go/pkg/mod/dubbo.apache.org/dubbo-go/[email protected]/protocol/jsonrpc/server.go:84
 +0x88
   panic({0x10258ad00?, 0x1038c87b0?})
        /usr/local/go/src/runtime/panic.go:783 +0xec
   
dubbo.apache.org/dubbo-go/v3/protocol/jsonrpc.(*Server).handlePkg(0x14000336500,
 {0x1028d41b8, 0x140001280c8})
        
/Users/guzemin/go/pkg/mod/dubbo.apache.org/dubbo-go/[email protected]/protocol/jsonrpc/server.go:156
 +0x950
   
dubbo.apache.org/dubbo-go/v3/protocol/jsonrpc.(*Server).Start.func1.1({0x1028d41b8,
 0x140001280c8})
        
/Users/guzemin/go/pkg/mod/dubbo.apache.org/dubbo-go/[email protected]/protocol/jsonrpc/server.go:248
 +0x34
   dubbo.apache.org/dubbo-go/v3/protocol/jsonrpc.accept.func1()
        
/Users/guzemin/go/pkg/mod/dubbo.apache.org/dubbo-go/[email protected]/protocol/jsonrpc/server.go:232
 +0x88
   created by dubbo.apache.org/dubbo-go/v3/protocol/jsonrpc.accept in goroutine 
114
        
/Users/guzemin/go/pkg/mod/dubbo.apache.org/dubbo-go/[email protected]/protocol/jsonrpc/server.go:221
 +0x384
   
   ### 💡 可能的解决方案
   
   ```go
   // 修改前 (server.go:153-161)
   if contentType != "application/json" && contentType != 
"application/json-rpc" {
       setTimeout(conn, httpTimeout)
       r.Header.Set("Content-Type", "text/plain")
       if errRsp := sendErrorResp(r.Header, 
[]byte(perrors.WithStack(err).Error())); errRsp != nil {
           logger.Warnf("sendErrorResp(header:%#v, error:%v) = error:%s",
               r.Header, perrors.WithStack(err), errRsp)
       }
       return
   }
   
   // 修改后
   if contentType != "application/json" && contentType != 
"application/json-rpc" {
       setTimeout(conn, httpTimeout)
       r.Header.Set("Content-Type", "text/plain")
       errMsg := "unsupported content type: " + contentType
       if errRsp := sendErrorResp(r.Header, []byte(errMsg)); errRsp != nil {
           logger.Warnf("sendErrorResp(header:%#v, error:%v) = error:%s",
               r.Header, errMsg, errRsp)
       }
       return
   }
   ```
   
   如果社区认可上述修复方案,我可以尽快提交 Pull Request。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to