smallnest / rpcx

Best microservices framework in Go, like alibaba Dubbo, but with more features, Scale easily. Try it. Test it. If you feel it's better, use it! 𝐉𝐚𝐯𝐚有𝐝𝐮𝐛𝐛𝐨, 𝐆𝐨𝐥𝐚𝐧𝐠有𝐫𝐩𝐜𝐱! build for cloud!
https://rpcx.io
Other
8.11k stars 1.17k forks source link

返回没有值的异常 #826

Closed adu202309 closed 12 months ago

adu202309 commented 12 months ago

func (c Client) RefreshConfig(ctx context.Context, args RefreshConfigReq) (reply *Resp, err error) { reply = &Resp{} err = c.xclient.Call(ctx, "RefreshConfig", args, reply) fmt.Println("$$$$$$$$$$$$$$$$$: ", reply) return reply, err }

打印结果: $$$$$$$$$$$$$$$$$:
panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x18 pc=0x169bb46] 请问怎么解决,reply 拿到的是一个空的

github.com/smallnest/rpcx v1.8.11 // indirect

adu202309 commented 12 months ago

func (c Client) RefreshConfig(ctx context.Context, args RefreshConfigReq) (reply *Resp, err error) { err = c.xclient.Call(ctx, "RefreshConfig", args, reply) fmt.Println("$$$$$$$$$$$$$$$$$: ", reply) return reply, err }

这样也一样拿到的是一个空nil

smallnest commented 12 months ago

贴全一些信息

smallnest commented 12 months ago

错误日志 + Resp数据结构

adu202309 commented 12 months ago

服务端代码: func (s ForwardImpl) BroadcastMsgToSrv(ctx context.Context, args forwardrpc.GameInternalMessage, reply *forwardrpc.Resp) (err error) { var resp = &forwardrpc.Resp{} resp, err = handles.BroadcastMsgToSrv(args) if err != nil { reply.Errmsg = resp.Errmsg reply.Errno = resp.Errno fmt.Println("@@@@@@@@@@@@@@: ", err) logging.Errorf("BroadcastMsgToSrv error args:%#v, reply:%#v, err: %s!", args, reply, err.Error()) return } reply.Errmsg = resp.Errmsg reply.Errno = resp.Errno return } 响应结构体: message Resp{ string errno = 1; // 错误码 string errmsg = 2; // 错误信息 } github.com/smallnest/rpcx v1.8.15

现在是客户端收不到err值,都是nil

adu202309 commented 12 months ago

客户端调用代码: func SendToGameSrvBroadcast(reg forwardrpc.GameInternalMessage) error { // 调用rpc 返回结果 // 设置客户端的超时时间为 5 秒 ctx, cancel := context.WithTimeout(context.Background(), 5time.Second) defer cancel() _, err := forwardrpcCli.BroadcastMsgToSrv(ctx, reg) if err != nil { fmt.Println(err.Error()) return errorx.Wrap(err) } return nil }

adu202309 commented 12 months ago

打印err: @@@@@@@@@@@@@@: 2023-11-13 12:25:49 | D:/go/src/forwardSrv/pkg/rpcClient/rpc_client.go:153 | can not found any server 2023-11-13 12:25:49 | D:/go/src/forwardSrv/pkg/handles/handlers.go:197 | can not found any server