gRPC Android客户端失去连接“太多ping",

问题描述:

Android grpc客户端从服务器收到GOAWAY消息,并显示太多ping"错误.现在,我意识到这可能是服务器端的问题,但是我认为问题在于客户端通道设置与服务器的设置不匹配.

Android grpc client is receiving GOAWAY from server with "too many pings" error. Now I realise that this is probably a server side issue, but I think the issue is that the client channel settings do not match that of the servers.

我有一个具有以下设置的C#gRPC服务器:

I have a C# gRPC server with the following settings:

List<ChannelOption> channelOptions = new List<ChannelOption>();
channelOptions.Add(new 
ChannelOption("GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS", 
1000));
channelOptions.Add(new 
ChannelOption("GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA", 0));
channelOptions.Add(new 
ChannelOption("GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS", 1));


this.server = new Server(channelOptions) {
    Services = { TerminalService.BindService(this) },
    Ports = {new ServerPort("0.0.0.0", 5000, 
 ServerCredentials.Insecure)}
};

在Android上,我具有以下频道设置:

On Android I have the following channel setup:

private val channel = ManagedChannelBuilder.forAddress(name, port)
        .usePlaintext()
        .keepAliveTime(10, TimeUnit.SECONDS)
        .keepAliveWithoutCalls(true)
        .build()

几分钟后(不过似乎是随机时间).我收到错误消息.我注意到,如果我在通话中流式传输数据,那么该错误就永远不会发生.仅当流上没有数据时.这使我相信问题在于,还需要在Android客户端上设置GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA.问题是我一生,我找不到在gRPC java上这些通道设置的设置位置.有人可以指出我在哪里可以设置这些频道设置吗?没有设置这些示例的示例.

After a few min (however seems to be a random time). I get the goaway error. I noticed that if I stream data on the call then the error never happens. It is only when there is no data on the stream. This leads me to believe the issue is that the GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA needs to be set on the Android client aswell. Problem is for the life of me I cannot find where to set these channel settings on gRPC java. Can someone point out to me where I can set these channel settings? There are no examples where these have been set.

指定的频道选项使用了错误的名称.像GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA之类的名称是"grpc.http2.max_pings_without_data"之类的C定义.

The channel options being specified are using the wrong names. Names like GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA are the C-defines for things like "grpc.http2.max_pings_without_data".

您可以通过查看 grpc_types.h .如果可用,您应该更喜欢在ChannelOptions中使用C#常量之一,但是在这种情况下,这似乎不是一个选择.

You can map from the C name to the key string by looking at grpc_types.h. You should prefer using one of the C# constants in ChannelOptions when it is available, but that doesn't seem to be an option in this case.

这些选项在Java ManagedChannelBuilder API中不可见,因为它们是服务器特定的设置.因此,它们在ServerBuilder上可见.参见 A8客户端保持活动供参考Java keepalive API.

These options are not visible in the Java ManagedChannelBuilder API because they are server-specific settings. So instead they are visible on the ServerBuilder. See A8 client-side keepalive for reference to the Java keepalive API.