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.08k stars 1.16k forks source link

请求出现 ERROR: rpcx: client protocol error: unexpected EOF #845

Closed gy0624ww closed 4 months ago

gy0624ww commented 6 months ago

问题: 客户端请求返回结果后会出现: 2024/03/22 10:18:49 client.go:764: ERROR: rpcx: client protocol error: unexpected EOF

请问是哪里的问题,因为是本机内部rpc调用,下面设置的时长不应该会出现超时断开的情况吧 @smallnest 辛苦帮忙看一下,这个是什么错误?下面代码配置的参数哪里有问题?

客户端代码如下:

func main() {
        // fmt.Println("client rpcx")
        // // rpcx client
        var oaid string
        flag.StringVar(&oaid, "oaid", "", "The Oaid to lookup")
        flag.Parse()
        d, _ := client.NewPeer2PeerDiscovery("tcp@"+"127.0.0.1:8972", "")
        opt := client.DefaultOption
        opt.CompressType = protocol.Gzip
        opt.SerializeType = protocol.MsgPack
        opt.Retries = 1
        opt.ConnectTimeout = 160 * time.Millisecond

        xclient := client.NewXClient("DeviceCrownFilter", client.Failfast, client.RandomSelect, d, opt)

        args := LookupRequest{
                Oaid: oaid,
        }

        for {
                reply := &LookupResponse{}
                err := xclient.Call(context.Background(), "Lookup", args, reply)
                if err != nil {
                        log.Println("failed to call: %v", err)
                }
                log.Printf("%s: %v", args.Oaid, reply.Exist)
                time.Sleep(300 * time.Millisecond)
        }
}

服务端代码配置如下:

engine := server.NewServer(
        server.WithReadTimeout(time.Duration(30)*time.Millisecond),
        server.WithWriteTimeout(time.Duration(30)*time.Millisecond),
    )

    filter.F = filter.NewCuckooFilter()
    fs := rpcx.NewFilterService(filter.F)
    // 路由初始化
    router := rpcx.NewRouter(fs)

    return rpcx.NewServer(engine, router)
smallnest commented 6 months ago

你这不是300 > 160 导致超时了?

gy0624ww commented 6 months ago

您发送给我的邮件 我已经收到了 所以,请您放心吧

gy0624ww commented 6 months ago

你这不是300 > 160 导致超时了?

这个160不是拨号的超时时间吗? for循环之前就连上了呀。 他和for循环里的请求间隔有什么关系呢?for循环里也没close之前的连接

smallnest commented 6 months ago

对,不是超时问题。 这个错误是服务端把链接关闭,导致客户端报错

gy0624ww commented 6 months ago

对,不是超时问题。 这个错误是服务端把链接关闭,导致客户端报错

嗯,原因找到了,是服务端设置的readtimeout ,因为客户端设置了sleep,服务端等待下次请求超时导致的。

最终解决是客户端设置了心跳,并且心跳间隔小于服务端的readtimeout 多谢

gy0624ww commented 4 months ago

您发送给我的邮件 我已经收到了 所以,请您放心吧