0

我有一个与客户端通信的 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)

我已经尝试搜索解决方案,唯一保持连接打开的“解决方案”是每 10 秒使用setInterval. 我读到 grpc 应该为您保持连接打开,甚至在本文丢失时重新连接。

如上所述,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"是应该每次 ping 服务器x ms

我是否做错了什么、遗漏或误解了一些重要的事情?

4

0 回答 0