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

metadata is not being sent

Open idangozlan opened this issue 6 years ago • 10 comments

I've tried all the possible variation of metadata (grpc metadata, row json), tried with callback, without callback (await), but it's seems like it's not sending any metadata.

On the official gRPC caller there is no any problem and I can see the metadata on the grpc server, so it's definitely problem of grpc-caller. I tried to debug it but I got blocked at some point (out of my understanding and I have no time to dig deep - sorry).

Is there any known issue about that which I missed?

idangozlan avatar Apr 27 '18 21:04 idangozlan

Hello can you provide some source code please? There are lots of examples in the tests such as this for unary or for request stream or response stream call.

bojand avatar Apr 27 '18 22:04 bojand

Sorry:

const PROTO_PATH = path.resolve(__dirname, './users.proto');
const client = caller('0.0.0.0:50051', PROTO_PATH, 'Users'); 
try {
    const res = await client.forgotPassword({ email: '[email protected]' }, { ip_address: '192.168.0.11' });
    console.log('RESPONSE: ', res);
  } catch (error) {
    console.log('ERROR: ', error);
  }

simple request, no stream.

idangozlan avatar Apr 27 '18 22:04 idangozlan

I think that should work as evident by the tests. Please provide a reproducible example and some more details including the protocol buffer definition, server code, nodejs, and grpc library versions.

bojand avatar Apr 28 '18 02:04 bojand

There you go:

test.proto:

syntax = "proto3";

package helloworld;

// The greeting service definition.
service Greeter {
  // Sends a greeting
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
  string name = 1;
}

// The response message containing the greetings
message HelloReply {
  string message = 1;
}

server.js:

const PROTO_PATH = `${__dirname}/test.proto`;

const grpc = require('grpc');

const helloProto = grpc.load(PROTO_PATH).helloworld;

/**
 * Implements the SayHello RPC method.
 */
function sayHello(call, callback) {
  console.log(call.request, call.metadata.getMap());
  callback(null, { message: `Hello ${call.request.name}` });
}

/**
 * Starts an RPC server that receives requests for the Greeter service at the
 * sample server port
 */
function main() {
  const server = new grpc.Server();
  server.addService(helloProto.Greeter.service, { sayHello });
  server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
  server.start();
}

main();

caller.js:

const PROTO_PATH = `${__dirname}/test.proto`;

const grpc = require('grpc');

const helloProto = grpc.load(PROTO_PATH).helloworld;

function main() {
  const client = new helloProto.Greeter(
    'localhost:50051',
    grpc.credentials.createInsecure(),
  );

  const meta = new grpc.Metadata();
  meta.add('ip_address', '192.168.0.11');

  client.sayHello({ name: 'world' }, meta, (err, response) => {
    console.log('Greeting:', response.message);
  });
}

main();

grpcCaller.js:

const PROTO_PATH = `${__dirname}/test.proto`;

const grpc = require('grpc');
const caller = require('grpc-caller');

function main() {
  const client = caller('0.0.0.0:50051', PROTO_PATH, 'Greeter');
  const meta = new grpc.Metadata();
  meta.add('ip_address', '192.168.0.11');

  client.sayHello({ name: 'world' }, meta, (err, response) => {
    console.log('Greeting:', response.message);
  });
}

main();

idangozlan avatar Apr 28 '18 17:04 idangozlan

Hmm I am still not able to reproduce this with latest master using Node 8.9. Can you maybe try the req_res branch of PR #11 and see if the problem still persists. Note that now you have to explicitly add grpc dependency in your package.json. Thanks!

bojand avatar Apr 28 '18 18:04 bojand

I can reproduce it also with the req_res branch.. What is the console logs that you are getting on your running server terminal?

im running with node 8.10.0

idangozlan avatar Apr 28 '18 18:04 idangozlan

client side:

~/dev/nodejs/grpc-caller-test node caller.js
Greeting: Hello world
~/dev/nodejs/grpc-caller-test

and on server:

~/dev/nodejs/grpc-caller-test node server.js
{ name: 'world' } { ip_address: '192.168.0.11',
  'user-agent': 'grpc-node/1.10.1 grpc-c/6.0.0-pre1 (osx; chttp2; glamorous)' }
^C
~/dev/nodejs/grpc-caller-test

bojand avatar Apr 28 '18 23:04 bojand

Haha, sure it will work, you are trying to run the original grpc caller :) try to run grpcCaller.js, the caller.js was just there to demonstrate how it should be..

idangozlan avatar Apr 29 '18 15:04 idangozlan

My apologies... I misread the code somehow heh. But still seems to works 😕

~/dev/nodejs/grpc-caller-test node grpcCaller.js
Greeting: Hello world
~/dev/nodejs/grpc-caller-test

and on the server side:

~/dev/nodejs/grpc-caller-test node server.js
{ name: 'world' } { ip_address: '192.168.0.11',
  'user-agent': 'grpc-node/1.10.1 grpc-c/6.0.0-pre1 (osx; chttp2; glamorous)' }
^C
~/dev/nodejs/grpc-caller-test

bojand avatar Apr 29 '18 16:04 bojand

Well, then idk what to say, for me it's not receiving the metadata. Any idea?

idangozlan avatar Apr 29 '18 16:04 idangozlan