0

我在连接到 NodeJS 服务器的 GRPC 客户端上使用 GRPC 版本:1.1.2 和 JDK 版本:1.8。Java 客户端能够正常连接,但是当我与客户端断开连接时,我总是在服务器端看到以下异常。

异常(仅在服务器上)

E0410 15:03:19.674531000 140735121084416 ssl_transport_security.c:439] SSL_read returned 0 unexpectedly.
E0410 15:03:19.674829000 140735121084416 secure_endpoint.c:185]        Decryption error: TSI_INTERNAL_ERROR

我正在通过以下调用关闭 GRPC Java 连接:

channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);  //channel is ManagedChannel

在进行此调用之前,我应该清理任何其他资源,还是应该使用替代机制彻底断开与服务器的连接?

编辑 我注意到,当我尝试以下操作时,我得到了同样的错误:

channel.shutdown();  

我在 Mac 上使用 OpenSSL - 我记得更改了默认 Mac 版本(OpenSSL 0.9.8zh 2016 年 1 月 14 日)。

grpc 中的secure_endpoint.c

 result = tsi_frame_protector_unprotect(ep->protector, message_bytes,
                                             &processed_message_size, cur,
                                             &unprotected_buffer_size_written);
      gpr_mu_unlock(&ep->protector_mu);
      if (result != TSI_OK) {
        gpr_log(GPR_ERROR, "Decryption error: %s",
                tsi_result_to_string(result));
        break;
      }
4

1 回答 1

1

ManagedChannel.shutdown()向服务器指示不应启动更多新的 RPC。所有现有的 RPC,尤其是流式 RPC 将继续运行。一旦所有这些 RPC 完成,ManagedChannel将关闭所有底层连接,通道将进入终止状态。

ManagedChannel 的设计类似于ExecutorService. 您可以做的一件事是确保您确实正确关闭,即在循环中调用 awaitTermination:

while (!channel.awaitTermination(5, TimeUnit.Second)) {
  System.err.println("Still not terminated.");
}
于 2017-04-11T22:22:01.733 回答