gRPC设置问题.出现间歇性RPC不可用错误 [英] Problem with gRPC setup. Getting an intermittent RPC unavailable error

查看:1131
本文介绍了gRPC设置问题.出现间歇性RPC不可用错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个grpc服务器和客户端,大多数情况下都可以正常工作,但是偶尔会出现传输正在关闭"错误:

I have a grpc server and client that works as expected most of the time, but do get a "transport is closing" error occasionally:

rpc error: code = Unavailable desc = transport is closing

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

I'm wondering if it's a problem with my setup. The client is pretty basic

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)

我正在做的另一件事是检查连接以查看它是打开,空闲还是正在连接,如果有则重新使用该连接.否则,请重拨.

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.

服务器没有任何特殊配置

Nothing special configuration is happening with the server

grpc.NewServer()

设置我可能正在做的grpc客户端/服务器时是否有常见错误?

Are there any common mistakes setting up a grpc client/server that I might be making?

推荐答案

我正在做的另一件事是检查连接以查看它是打开,空闲还是正在连接,如果有则重新使用该连接.否则,请重拨.

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会为您管理连接,并在需要时重新连接,因此除非有非常特殊的需求,否则创建后无需监视它.

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

这篇关于gRPC设置问题.出现间歇性RPC不可用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆