You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node.js使用gRPC Server Reflection连接失败问题求助

gRPC Server Reflection 连接SSL协商错误解决求助

我是gRPC新手,尝试通过gRPC Server Reflection从gRPC服务端获取服务信息,采用Node.js结合Express开发相关功能。每次运行代码都会抛出错误:
ReflectionRequestException [Error]: Error: 14 UNAVAILABLE: No connection established

详细调试日志显示,连接失败源于SSL协商错误:
005EF5EC01000000:error:0A000152:SSL routines:final_renegotiate:unsafe legacy renegotiation disabled

但使用grpcCurl访问同一端点gateway.grpc.com:443时,却能得到预期结果,希望获得解决帮助。

我的代码

const express = require("express");
const { GrpcReflection } = require('grpc-js-reflection-client');
const process = require('process');
var fs = require('fs');
const grpc =  require('@grpc/grpc-js');

const app = express();
app.use(express.json());


const PORT = process.env.PORT || 3000;
const HOST = "grpcb.in:9001";
const HOST1 = "gateway.grpc.com:443";


function getChannelCredentials(){
    return grpc.ChannelCredentials.createSsl();
}

function getServiceList(host){
    console.log("HOST is: " + host);
    try {
        (async()=> {
            const client = new GrpcReflection(
                host, 
                getChannelCredentials(),
                { 
                    "grpc.max_connection_age_ms": 10*1000,
                    'grpc.keepalive_time_ms': 10 * 1000,
                    // Keepalive ping timeout after 5 seconds, default is 20 seconds.
                    'grpc.keepalive_timeout_ms': 5 * 1000,
                    // Allow keepalive pings when there are no gRPC calls.
                    'grpc.keepalive_permit_without_calls': 1,
                    "grpc.initial_reconnect_backoff_ms": 1000,
                }
            );
            console.log(await client.listServices());
        })();
    }catch(e){
        console.log(e)
    }
}


app.listen(PORT,() =>{
    console.log("server running on port:", PORT);
    getServiceList(HOST1);
   
});

package.json配置

{
  "name": "grpc-server",
  "version": "1.0.0",
  "description": "Sample server to get grpc reflection objects using nodejs",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "grpc",
    "server-reflection"
  ],
  "author": "pawan",
  "license": "ISC",
  "dependencies": {
    "@grpc/grpc-js": "^1.8.17",
    "express": "^4.18.2",
    "fs": "^0.0.1-security",
    "grpc-js-reflection-client": "^1.2.1",
    "grpc-reflection-js": "^0.1.2",
    "lodash": "^4.17.21",
    "process": "^0.11.10"
  }
}

详细错误日志

pavenugopal@rws1-venugopal grpc-server % GRPC_VERBOSITY=debug GRPC_TRACE=channel,subchannel,call_stream,transport node index.js
server running on port: 3000
HOST is: gateway.grpc.com:443
D 2023-07-14T20:51:50.904Z | channel | (1) dns:gateway.grpc.int.ea.com:443 Channel constructed with options {
  "grpc.max_connection_age_ms": 10000,
  "grpc.keepalive_time_ms": 10000,
  "grpc.keepalive_timeout_ms": 5000,
  "grpc.keepalive_permit_without_calls": 1,
  "grpc.initial_reconnect_backoff_ms": 1000
}
D 2023-07-14T20:51:50.909Z | channel | (1) dns:gateway.grpc.com:443 createResolvingCall [0] method="/grpc.reflection.v1alpha.ServerReflection/ServerReflectionInfo", deadline=Infinity
D 2023-07-14T20:51:50.911Z | channel | (1) dns:gateway.grpc.int.ea.com:443 callRefTimer.ref | configSelectionQueue.length=1 pickQueue.length=0
D 2023-07-14T20:51:50.957Z | subchannel | (2)  Subchannel constructed with options {
  "grpc.max_connection_age_ms": 10000,
  "grpc.keepalive_time_ms": 10000,
  "grpc.keepalive_timeout_ms": 5000,
  "grpc.keepalive_permit_without_calls": 1,
  "grpc.initial_reconnect_backoff_ms": 1000
}
D 2023-07-14T20:51:50.957Z | channel | (1) dns:gateway.grpc.com:443 callRefTimer.unref | configSelectionQueue.length=1 pickQueue.length=0
D 2023-07-14T20:51:50.957Z | subchannel | (2) 159.153.190.73:443 IDLE -> CONNECTING
D 2023-07-14T20:51:50.958Z | transport | [object Object] creating HTTP/2 session to 159.153.190.73:443
D 2023-07-14T20:51:50.963Z | channel | (1) dns:gateway.grpc.com:443 createRetryingCall [1] method="/grpc.reflection.v1alpha.ServerReflection/ServerReflectionInfo"
D 2023-07-14T20:51:50.964Z | channel | (1) dns:gateway.grpc.com:443 createLoadBalancingCall [2] method="/grpc.reflection.v1alpha.ServerReflection/ServerReflectionInfo"
D 2023-07-14T20:51:50.964Z | channel | (1) dns:gateway.grpc.com:443 callRefTimer.ref | configSelectionQueue.length=0 pickQueue.length=1
D 2023-07-14T20:51:51.181Z | transport | [object Object] connection failed with error 005EF5EC01000000:error:0A000152:SSL routines:final_renegotiate:unsafe legacy renegotiation disabled:ssl/statem/extensions.c:893:

D 2023-07-14T20:51:51.182Z | subchannel | (2) 159.153.190.73:443 CONNECTING -> TRANSIENT_FAILURE
D 2023-07-14T20:51:51.182Z | channel | (1) dns:gateway.grpc.com:443 callRefTimer.unref | configSelectionQueue.length=0 pickQueue.length=0
/Users/pavenugopal/Documents/Projects/grpc-server/node_modules/grpc-js-reflection-client/dist/GrpcReflection.js:61
                throw new Exceptions_1.ReflectionRequestException(err);
                ^

ReflectionRequestException [Error]: Error: 14 UNAVAILABLE: No connection established
    at ClientDuplexStreamImpl.<anonymous> (/Users/pavenugopal/Documents/Projects/grpc-server/node_modules/grpc-js-reflection-client/dist/GrpcReflection.js:61:23)
    at ClientDuplexStreamImpl.emit (node:events:512:28)
    at Object.onReceiveStatus (/Users/pavenugopal/Documents/Projects/grpc-server/node_modules/@grpc/grpc-js/build/src/client.js:419:28)
    at Object.onReceiveStatus (/Users/pavenugopal/Documents/Projects/grpc-server/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:323:181)
    at /Users/pavenugopal/Documents/Projects/grpc-server/node_modules/@grpc/grpc-js/build/src/resolving-call.js:94:78
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)

Node.js v20.4.0

内容的提问来源于stack exchange,提问作者Pawan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 20:50:56