Java netty / okhttp gRPC客户端间歇性抛出UNAVAILABLE:尝试连接时出现io异常

时间:2019-10-21 04:59:44

标签: netty okhttp grpc-java

我尝试使用Java GRPC客户端(netty和okhttp)连接到Go服务器。但是他们两个都抛出了UNAVAILABLE:io间歇性地异常。

这种情况是随机发生的,我们不知道是什么原因导致了这种行为。我们发现该请求未到达Go服务器。

用于连接的阻塞存根类似于:

public SomeServiceGrpc.SomeServiceBlockingStub getBlockingStub() {

        ManagedChannel channel = OkHttpChannelBuilder
                .forAddress(configuration.getHost(), configuration.getPort())
                .useTransportSecurity()
                .keepAliveTime(1, TimeUnit.MINUTES)
                .keepAliveTimeout(5, TimeUnit.SECONDS)
                .intercept(deadlineInterceptor)
                .build();
        return SomeServiceGrpc.newBlockingStub(channel);
    }

这些是用于okhttp和protobuf的库:

    compile 'io.grpc:grpc-okhttp:1.21.0'
    compile 'io.grpc:grpc-protobuf:1.20.0'
    compile 'io.grpc:grpc-stub:1.20.0'

这些是用于netty和protobuf的库:

    compile group: 'io.grpc', name: 'grpc-netty', version: '1.22.1'
    compile group: 'io.netty', name: 'netty-handler', version: '4.1.35.Final'
    compile group: 'io.netty', name: 'netty-tcnative-boringssl-static', version: '2.0.25.Final'
    compile 'io.grpc:grpc-protobuf:1.20.0'
    compile 'io.grpc:grpc-stub:1.20.0'

任何帮助或潜在客户的赞赏。

1 个答案:

答案 0 :(得分:1)

通过在客户端和服务器端将keepAliveWithoutCalls添加为true来解决此问题。