【问题标题】:Java netty/okhttp gRPC client throwing intermittent UNAVAILABLE: io exception while trying to connectJava netty/okhttp gRPC 客户端在尝试连接时抛出间歇性 UNAVAILABLE:io 异常
【发布时间】:2019-10-21 04:59:44
【问题描述】:

我正在尝试使用 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'

任何帮助或领导表示赞赏。

【问题讨论】:

  • 为什么要在不同版本的grpc中混用?我看到 1.21.0 1.20.0 1.22.1 你有完整的堆栈跟踪吗?
  • @creamsoup 没有特别的原因,版本差异可能是个问题吗?没有可用的堆栈跟踪

标签: netty okhttp grpc-java


【解决方案1】:

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

public SomeServiceGrpc.SomeServiceBlockingStub getBlockingStub() {

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-14
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 1970-01-01
    • 2018-04-05
    相关资源
    最近更新 更多