GRPC io.grpc.StatusRuntimeException:不可用:io 异常

Sta*_*iuk 5 grpc grpc-java

代码模型看起来像

 Iterator iterator = grpc.invokeSomeRequest(requestData) //returns iterator
 while(iterator.hasNext()){
     //do some code.
 }
Run Code Online (Sandbox Code Playgroud)

有时,错误会发生在iterator.hasNext()堆栈跟踪中:

UNAVAILABLE: io exception               
io.grpc.StatusRuntimeException: UNAVAILABLE: io exception                                                                                                                                
     at io.grpc.Status.asRuntimeException(Status.java:533) 
Run Code Online (Sandbox Code Playgroud)

grpc的版本是1.21.0

我发现这个问题最有可能出现在 grpc 上。我可能是错的。解决这个问题的最佳方法是什么?

Kar*_*ran 0

对我来说,当我使用时,这个问题就解决了

channelBuilder = NettyChannelBuilder.forAddress(host, port).usePlaintext().enableRetry().keepAliveTime(10,TimeUnit.SECONDS);
Run Code Online (Sandbox Code Playgroud)

代替

channelBuilder = NettyChannelBuilder.forAddress(host, port);
channelBuilder.negotiationType(NegotiationType.TLS).enableRetry().keepAliveTime(10,TimeUnit.SECONDS);
channelBuilder.sslContext(
              GrpcSslContexts.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build())
Run Code Online (Sandbox Code Playgroud)