duanjiao8007 2018-10-25 15:39 采纳率: 100%
浏览 2401
已采纳

gRPC设置问题。 出现间歇性RPC不可用错误

我有一个grpc服务器和客户端,大部分时间都能正常运行,但是偶尔会收到“传输正在关闭”错误:

rpc error: code = Unavailable desc = transport is closing

我想知道我的设置是否有问题。 客户端很基础

connection, err := grpc.Dial(address, grpc.WithInsecure(), grpc.WithBlock())
pb.NewAppClient(connection)
defer connection.Close()

并以类似超时的方式拨打电话

ctx, cancel := context.WithTimeout(ctx, 300*time.Millisecond)
defer cancel()

client.MyGRPCMethod(ctx, params)

我正在做的另一件事是检查连接来查看它是处于打开,空闲还是正在连接状态,如果有则重新使用该连接。 否则,请重拨。 p>

服务器没有任何特殊配置

grpc.NewServer()

设置grpc客户端/服务器时是否会遇到一些常见错误?

  • 写回答

3条回答 默认 最新

  • douwen0647 2018-10-31 20:33
    关注

    One other thing I'm doing is checking the connection to see if it's either open, idle or connecting, and reusing the connection if so. Otherwise, redialing.

    grpc will manage your connections for you, reconnecting when needed, so you should never need to monitor it after creating it unless you have very specific needs.

    "transport is closing" has many different reasons for happening; please see the relevant question in our FAQ and let us know if you still have questions: https://github.com/grpc/grpc-go#the-rpc-failed-with-error-code--unavailable-desc--transport-is-closing

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?