【问题标题】:How do I handle GRPC disconnects?如何处理 GRPC 断开连接?
【发布时间】:2020-04-17 13:32:40
【问题描述】:

在 NestJS 中,我有一个有时会断开连接的 GRPC 客户端。如果发生断开连接,NestJS 将不再运行任何代码并强制我重新启动它。

如何处理 GRPC 客户端断开连接?有事件监听器吗?

我想要这些错误事件:

  • Error: 14 UNAVAILABLE: failed to connect to all addresses
  • Error: 2 UNKNOWN: Stream removed

【问题讨论】:

  • gRPC 客户端断开连接时,您是否看到任何特定的错误消息或其他输出?
  • 嘿@murgatroid99,其中两个错误事件是:-Error: 14 UNAVAILABLE: failed to connect to all addresses-Error: 2 UNKNOWN: Stream removed

标签: nestjs


【解决方案1】:

添加以下行可防止 Node 进程崩溃并让用户有机会处理 GRPC 断开连接:

process.on('uncaughtException', function(err) {
  console.log(err)
})

【讨论】:

    猜你喜欢
    • 2015-05-01
    • 2016-02-25
    • 2012-10-18
    • 1970-01-01
    • 2018-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多