简体   繁体   English

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

[英]gRPC Android Client losing connection “too many pings”

Android grpc client is receiving GOAWAY from server with "too many pings" error. Android grpc客户端从服务器收到GOAWAY消息,并显示“太多ping”错误。 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. 现在,我意识到这可能是服务器端的问题,但是我认为问题在于客户端通道设置与服务器的设置不匹配。

I have a C# gRPC server with the following settings: 我有一个具有以下设置的C#gRPC服务器:

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)}
};

On Android I have the following channel setup: 在Android上,我具有以下频道设置:

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

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. 这使我相信问题在于,还需要在Android客户端上设置GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA。 Problem is for the life of me I cannot find where to set these channel settings on gRPC java. 问题是我一生,我找不到在gRPC java上设置这些通道设置的位置。 Can someone point out to me where I can set these channel settings? 有人可以指出我在哪里可以设置这些频道设置吗? There are no examples where these have been set. 没有设置这些示例的示例。

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_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA之类的名称是诸如"grpc.http2.max_pings_without_data"类的C定义。

You can map from the C name to the key string by looking at grpc_types.h . 您可以通过查看grpc_types.h从C名称映射到键字符串。 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. 您应该更喜欢在ChannelOptions使用其中一个C#常量,但是在这种情况下,这似乎不是一个选择。

These options are not visible in the Java ManagedChannelBuilder API because they are server-specific settings. 这些选项在Java ManagedChannelBuilder API中不可见,因为它们是服务器特定的设置。 So instead they are visible on the ServerBuilder. 因此,它们在ServerBuilder上可见。 See A8 client-side keepalive for reference to the Java keepalive API. 请参阅A8客户端keepalive以获取对Java keepalive API的引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM