grpc-node icon indicating copy to clipboard operation
grpc-node copied to clipboard

Not able to pass multiple machine ips from client side of grpc server

Open vishalthakuriya opened this issue 3 years ago • 8 comments

Problem description

I have two servers running trying to pass the both the ips to grpc client but still no connection is happing we don't have any DNS name is still possible ?

Reproduction steps

create 2 server and from client-side try to pass both the server ips to connect to server but it is not working adding full code below #Please check whole code below

let target = "10.109.121.95:2121,10.109.121.117:2121";
let client = new hello_proto.ClassifierRequestHandler(target,
                                       grpc.credentials.createInsecure());

Environment

  • linux
  • Node versionv 14.17.3

Additional context

Add any other context about the problem here. If possible, attach full logs. Do not try to omit anything for brevity, but instead include absolutely everything. Please try and set your operating system's locale to English, so that logs contain error messages in the English language.

let PROTO_PATH = __dirname + '/../../protos/pe_classifier.proto';
const __          = require('lodash');
let parseArgs = require('minimist');
let grpc = require('@grpc/grpc-js');
let protoLoader = require('@grpc/proto-loader');
let packageDefinition = protoLoader.loadSync(
    PROTO_PATH,
    {keepCase: true,
     longs: String,
     enums: String,
     defaults: false,
     oneofs: true
    });
let hello_proto = grpc.loadPackageDefinition(packageDefinition).classifier;

function main() {
  let argv = parseArgs(process.argv.slice(2), {
    string: 'target'
  });
  let target;
  if (argv.target) {
    target = argv.target;
  } else {
    target = "10.109.121.95:2121,10.109.121.117:2121";
  }

  let client = new hello_proto.ClassifierRequestHandler(target,
                                       grpc.credentials.createInsecure());
 
  let test =  {"abcd":"test","sfvecmd5":"12344","version":2,"sensitivity":"L","filetype":10}
  client.GetClassification(test , function(err, response) {
   
    console.log('this is responseeeee :',typeof(response) );
  });
  
}

main();

vishalthakuriya avatar Mar 24 '22 05:03 vishalthakuriya

@murgatroid99 Please help we have blocked because of this any help will be really appreciated thanks in advance

vishalthakuriya avatar Mar 24 '22 07:03 vishalthakuriya

Multiple IP addresses in the target string are only supported when using the ipv4 and ipv6 address schemes. Since you are using IPv4 addresses, you need to use the ipv4 scheme, so your target string should be ipv4:///10.109.121.95:2121,10.109.121.117:2121.

Please note that by default, gRPC will only connect to a single address in the list. If you would prefer that it connect to all addresses and round robin requests between them, the instructions here will help you do that: https://github.com/grpc/grpc-node/issues/1307#issuecomment-601312421.

murgatroid99 avatar Mar 24 '22 09:03 murgatroid99

@murgatroid99 Thanks for the reply but unfortunately it is not working

target="10.109.121.95:2121" - working as expected

target="10.109.121.117:2121" - working as expected

target = "ipv4:///10.109.121.95:2121,10.109.121.117:2121" is this is proper way to define or anything is missing

  • throwing error -- err {"code":14,"details":"Name resolution failed for target dns:ipv4:///10.109.121.95:2121,10.109.121.117:2121","metadata":{"internalRepr":{},"options":{}}}

vishalthakuriya avatar Mar 24 '22 10:03 vishalthakuriya

@murgatroid99 sir please check once if you can find any issue thanks alot

vishalthakuriya avatar Mar 24 '22 12:03 vishalthakuriya

Support for the ipv4 was added in grpc-js version 1.3.0. Please upgrade your dependency on grpc-js to use that functionality.

Also, an update to my previous statement: while the string I gave should work, the format ipv4:10.109.121.95:2121,10.109.121.117:2121 is preferred.

murgatroid99 avatar Mar 24 '22 20:03 murgatroid99

@murgatroid99 Thanks for the response with grpc-js version 1.5.9 able to pass the connection in ipv4:10.109.121.95:2121,10.109.121.117:2121 this format and but the client is only connecting to the single server first one in my case all the requests are going to 10.109.121.95 even I have added service config also in code please have a look below

target = "ipv4:10.109.121.95:2121,10.109.121.117:2121"; const serviceConfig = { 'loadBalancingConfig': [ { round_robin: {} } ] } const client = new hello_proto.Classifier(target, grpc.credentials.createInsecure(), { 'grpc.service_config': JSON.stringify(serviceConfig) });

And this is all of are versions

"@grpc/proto-loader": "0.6.9", "async": "3.2.2", "co": "^4.6.0", "google-protobuf": "3.19.4", "@grpc/grpc-js": "1.5.7",

vishalthakuriya avatar Mar 25 '22 04:03 vishalthakuriya

@murgatroid99 please check if you have any solution here thanks for replying

vishalthakuriya avatar Mar 25 '22 04:03 vishalthakuriya

There could be multiple reasons for it to behave that way. If you run your code with the environment variables GRPC_TRACE=all and GRPC_VERBOSITY=DEBUG, the log output will give more information about what is happening.

murgatroid99 avatar Mar 25 '22 22:03 murgatroid99