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

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条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?