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.

Error: grpc-js doesn't work with FlatBuffer message (message.copy is not a function)

See original GitHub issue

Problem description

gprc (native node module) works with FlatBuffers message but pure js version seems to be buggy with it.

Reproduction steps

  1. Write a .fbs schema file with RPC service, generate JS, TS definitions
  2. In JS code, create a message using FlatBuffers builder, example:
    const server = new PAuthClient(ServerURL, ServerCertificate)
    const builder = new flatbuffers.Builder() // create message
    
    const email = builder.createString(this.email) // add fields to message
    const password = builder.createString(this.password)  // add fields to message
    
    const service = builder.createString('___')
    const root = PAuthRequest.createPAuthRequest(builder, email, password, service)
    builder.finish(root)
    
    const buffer = PAuthRequest.getRootAsPAuthRequest(new flatbuffers.ByteBuffer(builder.asUint8Array()))

    // below code works with grpc native, but with grpc-js, errors printed:
    // INTERNAL: message.copy is not a function
    server.Authenticate(buffer, (err, response) => {
    })

Environment

  • OS name, version and architecture: Ubuntu 20.04 amd64
  • Node version: v12.13.0
  • Node installation method: nvm
  • Package name and version: grpc-js - 1.5.10

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
murgatroid99commented, Mar 25, 2022

I think this is likely to be an error in the code generator. The object that ends up being message is the output of a serialize function, which is a function signature that returns a Buffer in both libraries. Since the Buffer class has a copy method, I can only assume that some other object made its way into that code path, and since the serialize function is provided by the code generator, that’s where the problem probably is.

My guess is that, since neither library calls every method of the Buffer class, the FlatBuffer code generator was able to get away with providing some other object that happens to implement the subset of the Buffer API that the grpc library uses. But that is just coincidental compatibility.

0reactions
manhnt9commented, Mar 30, 2022

Yep, I should try upgrading to new FlatBuffers since I saw this line in its latest release: “Overhaul of TypeScript support.” Thanks !

Can be closed for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node grpc client error: TypeError: _d.substring is not a function
I have encountered strange issue and I am unable to make a call to my grpc server from node. I am using: "@grpc/grpc-js":...
Read more >
grpc/grpc - Gitter
Hi, everybody. I've been struggling with passing a JSON with Message values back and forth between systems. message Result { struct/value/any? variables =...
Read more >
FlatBuffers: Tutorial - Google
This tutorial provides a basic example of how to work with FlatBuffers. We will step through a simple example application, which shows you...
Read more >
Protocol Buffers Crash Course - YouTube
hard to use with JSON based application ( Javascript /browser) protoc compiler protoc --js_out=import_style=commonjs,binary:. employees.proto ...
Read more >
Custom encoding: Go implementation in net/rpc vs grpc and ...
And the fact that Flatbuffers doesn't need to recreate the entire ... Helper function to deal with writing and parsing header for the ......
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