question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@grpc/grpc-js: duplex streams of node.js doesn't fire data event

See original GitHub issue

Problem description

I send data to the server by using the write method provided by duplex stream. And the proto code I use is generated by grpc-tools. But i can’t get the data event fired. And everything works fine if I use grpc package instead of @grpc/grpc-js.

Reproduction steps

proto file is defined as below:

message Command {
  enum Type {
     PING = 0;
  }
  string id = 1;
  Type type = 2;
  bytes payload = 3; // payload is not required if type is 0
}

message CommandResponse {
   string reply_id = 1;
}

service Connect {
   rpc Connect(stream CommandV2) returns (stream CommandResponseV2) {}
}

I get ConnectClient after generating code by using grpc-tools. Then i create a connectClient instance.

  const connectClient = new ConnectClient(backendAddr, grpc.credentials.createSsl());
  const call = connectClient.connect(getGrpcMetaData()); // getGrpcMetaData is a function returns grpc.Metadata
  setInterval(() => {
    call.write({
        type: 0,
        id: '8888-899-0090'
    });
  }, 10000)
  call.on('data', (chunk) => {
    console.log(chunk); // this line of code will not be executed.
  });

Environment

  • OS name, version and architecture: MacOS Catalina 10.15.4
  • Node version 14.3.0
  • Node installation method: yarn
  • If applicable, compiler version: vs code 1.45.0
  • Package name and version @grpc/grpc-js@1.0.4

Additional context

The @grpc/grpc-js package is used in an electron project.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
murgatroid99commented, Jun 24, 2020

More specifically, the first message gets through to the server, then the client writes the next message to the HTTP2 stream, but the callback for that write operation is never called, and the server never sees that second message. Then all of the messages after that just pile up in the client’s buffer.

In other words, the gRPC library is behaving as expected here, and Electron’s version of the HTTP2 internals is not behaving as expected. So, this is an Electron bug.

I checked, and the code you have works just fine in the main process.

The simplest solution here is to not try to do this in the renderer. Electron’s “main”/“renderer” split exists for a reason. You should do rendering operations in the renderer process, and other operations like network requests in the main process.

0reactions
117spartacommented, Jun 24, 2020

OK,I try the solution you provided and it works. Thank you for your help! I guess I can close this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node duplex stream doesn't actually emit data when read
I've stumbled across duplex streams and started playing with them a bit to get my feet wet, but everything I try seems to...
Read more >
Basics tutorial | Node - gRPC
This event fires with each Feature message object until there are no more messages. Errors in the 'data' callback will not cause the...
Read more >
Stream | Node.js v19.3.0 Documentation
Socket instances are Duplex streams whose Readable side allows consumption of data received from the socket and whose Writable side allows writing data...
Read more >
gRPC - Microservices - A progressive Node.js framework
gRPC is a modern, open source, high performance RPC framework that can run in any environment. It can efficiently connect services in and...
Read more >
Events and Streams in Node.js - codeburst
Once inside the event handler, you can call the read function on the stream to read data from the stream. The most important...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found