在非活动时间如何保持grpc-js客户端连接打开(活动)?

时间:2020-06-23 12:59:11

标签: grpc http2 keep-alive grpc-js

我有一个与客户端通信的grpc服务器流式RPC。客户端未收到来自服务器的通信时,将引发错误。错误是:

Error: 13 INTERNAL: Received RST_STREAM with code 2
    at Object.callErrorFromStatus (/app/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
    at Object.onReceiveStatus (/app/node_modules/@grpc/grpc-js/build/src/client.js:328:49)
    at Object.onReceiveStatus (/app/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:304:181)
    at Http2CallStream.outputStatus (/app/node_modules/@grpc/grpc-js/build/src/call-stream.js:116:74)
    at Http2CallStream.maybeOutputStatus (/app/node_modules/@grpc/grpc-js/build/src/call-stream.js:155:22)
    at Http2CallStream.endCall (/app/node_modules/@grpc/grpc-js/build/src/call-stream.js:141:18)
    at ClientHttp2Stream.stream.on (/app/node_modules/@grpc/grpc-js/build/src/call-stream.js:410:22)
    at ClientHttp2Stream.emit (events.js:198:13)
    at emitCloseNT (internal/streams/destroy.js:68:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
Emitted 'error' event at:
    at Object.onReceiveStatus (/app/node_modules/@grpc/grpc-js/build/src/client.js:328:28)
    at Object.onReceiveStatus (/app/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:304:181)
    [... lines matching original stack trace ...]
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)

我尝试搜索解决方案,唯一使连接保持打开状态的“解决方案”是使用setInterval每10秒手动ping一次客户端。我读到grpc应该可以为您保持连接打开,甚至在丢失in this article时也可以重新连接。

如上所述,KeepAlive提供了一个宝贵的好处:通过发送HTTP / 2 PING来定期检查连接的运行状况,以确定连接是否仍处于活动状态。

我设置客户端的方式如下

var grpc = require('@grpc/grpc-js');
require('dotenv').config({path:'/app/.env'});
var responderProto = grpc.loadPackageDefinition(packageDefinition).responder;
var client = new responderProto.ResponderService(process.env.GRPC_HOST_AND_PORT,
        grpc.credentials.createInsecure(),
        {
            "grpc.http2.max_pings_without_data" : 0,
            "grpc.keepalive_time_ms": 10000,
            "grpc.keepalive_permit_without_calls" : 1

        });

我的理解是,"grpc.keepalive_time_ms"应该每x ms ping服务器一次

我是在做错什么,遗失或误解了某些基本内容吗?

0 个答案:

没有答案