最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - GRPC client Error: 14 UNAVAILABLE: failed to connect to all addresses - Stack Overflow

programmeradmin3浏览0评论

Im trying to test my grpc client connection using below code. I have core grpc server and using node js grpc client to connect. But getting "failed to connect to all addresses" error. BUt able to connect grpc server to grpc client. Any help much appreciated.

Not sure if im missing anything from below grpc client code.

'use strict';
//Same as the other projects we import fs for reading documents, in this case employees.js json
const fs = require('fs');

//Importing GRPC and the proto loader
const grpc = require('grpc');
const loader = require('@grpc/proto-loader');



//reads the proto
const packageDefinition = loader.loadSync('Repository.proto', {
  keepCase: false,
  longs: String,
  enums: String, 
  defaults: true,
  oneofs: true
});



//Loads the proto file to be used in constant pkg
const pkg = grpc.loadPackageDefinition(packageDefinition);

//Creates server
const PORT = 5001;

//console.log(pkg);

const client = new pkg.repository.Repository('localhost:5001', grpc.credentials.createInsecure());

 client.GetUpdates({}, function (err, response) {
    console.log("----Response error----");
    if (err) {
    
      console.log(err);
  } else {
      console.log(response);
  }
});

im getting below error:

{ Error: 14 UNAVAILABLE: failed to connect to all addresses
    at Object.exports.createStatusError (/mnt/c/Users/ht9638/Desktop/workspace/current-workspace/gRPCNodeJS/firstService/node_modules/grpc/src/mon.js:91:15)
    at Object.onReceiveStatus (/mnt/c/Users/ht9638/Desktop/workspace/current-workspace/gRPCNodeJS/firstService/node_modules/grpc/src/client_interceptors.js:1209:28)
    at InterceptingListener._callNext (/mnt/c/Users/ht9638/Desktop/workspace/current-workspace/gRPCNodeJS/firstService/node_modules/grpc/src/client_interceptors.js:568:42)
    at InterceptingListener.onReceiveStatus (/mnt/c/Users/ht9638/Desktop/workspace/current-workspace/gRPCNodeJS/firstService/node_modules/grpc/src/client_interceptors.js:618:8)
    at callback (/mnt/c/Users/ht9638/Desktop/workspace/current-workspace/gRPCNodeJS/firstService/node_modules/grpc/src/client_interceptors.js:847:24)
  code: 14,
  metadata: Metadata { _internal_repr: {}, flags: 0 },
  details: 'failed to connect to all addresses' }

Can someone please help me on this issue.

Im trying to test my grpc client connection using below code. I have core grpc server and using node js grpc client to connect. But getting "failed to connect to all addresses" error. BUt able to connect grpc server to grpc client. Any help much appreciated.

Not sure if im missing anything from below grpc client code.

'use strict';
//Same as the other projects we import fs for reading documents, in this case employees.js json
const fs = require('fs');

//Importing GRPC and the proto loader
const grpc = require('grpc');
const loader = require('@grpc/proto-loader');



//reads the proto
const packageDefinition = loader.loadSync('Repository.proto', {
  keepCase: false,
  longs: String,
  enums: String, 
  defaults: true,
  oneofs: true
});



//Loads the proto file to be used in constant pkg
const pkg = grpc.loadPackageDefinition(packageDefinition);

//Creates server
const PORT = 5001;

//console.log(pkg);

const client = new pkg.repository.Repository('localhost:5001', grpc.credentials.createInsecure());

 client.GetUpdates({}, function (err, response) {
    console.log("----Response error----");
    if (err) {
    
      console.log(err);
  } else {
      console.log(response);
  }
});

im getting below error:

{ Error: 14 UNAVAILABLE: failed to connect to all addresses
    at Object.exports.createStatusError (/mnt/c/Users/ht9638/Desktop/workspace/current-workspace/gRPCNodeJS/firstService/node_modules/grpc/src/mon.js:91:15)
    at Object.onReceiveStatus (/mnt/c/Users/ht9638/Desktop/workspace/current-workspace/gRPCNodeJS/firstService/node_modules/grpc/src/client_interceptors.js:1209:28)
    at InterceptingListener._callNext (/mnt/c/Users/ht9638/Desktop/workspace/current-workspace/gRPCNodeJS/firstService/node_modules/grpc/src/client_interceptors.js:568:42)
    at InterceptingListener.onReceiveStatus (/mnt/c/Users/ht9638/Desktop/workspace/current-workspace/gRPCNodeJS/firstService/node_modules/grpc/src/client_interceptors.js:618:8)
    at callback (/mnt/c/Users/ht9638/Desktop/workspace/current-workspace/gRPCNodeJS/firstService/node_modules/grpc/src/client_interceptors.js:847:24)
  code: 14,
  metadata: Metadata { _internal_repr: {}, flags: 0 },
  details: 'failed to connect to all addresses' }

Can someone please help me on this issue.

Share Improve this question asked Sep 30, 2020 at 13:41 harish511harish511 2072 gold badges3 silver badges6 bronze badges 5
  • probably a dumb suggestion, but is it the correct port? – Eamonn McEvoy Commented Sep 30, 2020 at 13:42
  • Yes. That is correct port. – harish511 Commented Sep 30, 2020 at 13:47
  • 1 I can't help but notice that you are using port 5001, which is similar to the port monly used in the gRPC examples, 50051. Are you sure you got the port number right? – murgatroid99 Commented Sep 30, 2020 at 18:52
  • As a sanity check, could you try calling the grpc endpoint using BloomRPC - github./uw-labs/bloomrpc I think you should do a quick test with 50051 also. – Eamonn McEvoy Commented Oct 1, 2020 at 8:25
  • I don't see anything outright wrong with your example, but connections from nodejs to C# server is something we test continously in our test suite, so my guess is that you've some likely setup something incorrectly (perhaps the server is listening on a different port or so). Feel free to try github./fullstorydev/grpcurl to test requests to your server manually. – Jan Tattermusch Commented Oct 12, 2020 at 14:37
Add a ment  | 

1 Answer 1

Reset to default 2

I have the same issue when I tried to follow gRPC nodejs tutorials from the official documentation.

Root cause(for me): port 50051 is the default port used from the main documentation, when I checked the list of the ports being used on my laptop, it turned out that port 50051 was used by "NVIDIA Web Helper.exe".

How I found this out: I tried to change the port slightly to 50052 and console.log the err and it shows as expected

发布评论

评论列表(0)

  1. 暂无评论