grpc / grpc-web

gRPC for Web Clients
https://grpc.io
Apache License 2.0
8.59k stars 765 forks source link

Getting {code: 2, message: 'Incomplete response'} code : 2 message : "Incomplete response" [[Prototype]] : Object #1356

Closed SimulShift closed 9 months ago

SimulShift commented 1 year ago

I am sending the Status.OK code but with a simple ping pong example, but the browser always gets a code: 2 "Incomplete Message". Everything else is working. If I set the error as null, the RPC gets called correctly and everything functions. grpc-web just seems to have an issue decoding the error messages. Maybe my version of grpc-js is too high ( I am using grpc-js 1.9.1 but the example is using 1.1.8). I tried downgrading but got errors in the node_modules

export const pingPongServiceHandlers: PingPongServiceHandlers = {
  ping: (call, callback) => {
    console.log('ping')
    callback(
      {
        code: Status.OK,
        message: 'pong',
        details: 'pong',
        metadata: call.metadata,
        name: 'pong',
      },
      null,
    )
  },
}
SimulShift commented 1 year ago

after more digging it only happens when using Status.OK. Status.OK is code: 0 that may be causing some weird typescript conversion issues where its interpreting 0 as falsey rather than a status code. Other status codes are getting sent correctly

sampajano commented 1 year ago

@SimulShift Thanks for the report!

It is surprising for me to hear the basic case doesn't work.. since we should have test coverages for them..

I wonder if you are able to reproduce following our Typescript demo here (either using Docker or manual run)? https://github.com/grpc/grpc-web/tree/master/net/grpc/gateway/examples/echo/ts-example#readme

If you are able to, would you mind creating a test PR demo'ing how to reproduce?

Thanks!

SimulShift commented 1 year ago

@sampajano sure thing, here is a PR

https://github.com/grpc/grpc-web/pull/1358

sampajano commented 11 months ago

@SimulShift Thanks so much for providing the PR example! (And sorry for the delay in response!)

I was able to reproduce this issue.

Although, I'm wondering if this is related to the behavior of the Node server, given that i have no expertise in that.. I'll check with out Node owner :)


@murgatroid99 Hi! Could you help verifying that the following is a valid way of returning a successful RPC response?

callback({code: 0, message: ...});

(Also I wasn't able to find documentation on the APIs on Node github. Would appreciate any pointers 😃)

Do you see some way it's causing very different wire encoding than if when, e.g. {code: 1, ...} is used, so that it can lead to decoding failure on the grpc-web (or even Envoy) side?

Thanks a lot!

murgatroid99 commented 11 months ago

The first parameter indicates that there is an error. You shouldn't be using it with an OK status. If the call is successful that parameter should be null.

The reason you are seeing the "Incomplete response" error is that the client is expecting a message, but only gets trailers with an OK status.

murgatroid99 commented 11 months ago

The Node gRPC API docs are here. They're for the old library so they're out of date, but they're still mostly right.

murgatroid99 commented 11 months ago

Also, I just noticed that you are trying to send a null response with an OK status. That is not valid; you need to send an actual response message for a unary response.

sampajano commented 11 months ago

The first parameter indicates that there is an error. You shouldn't be using it with an OK status. If the call is successful that parameter should be null.

The reason you are seeing the "Incomplete response" error is that the client is expecting a message, but only gets trailers with an OK status.

Also, I just noticed that you are trying to send a null response with an OK status. That is not valid; you need to send an actual response message for a unary response.

@murgatroid99 Thanks so much for clarifying! Happy to hear it's not a client-side bug! 😄

@SimulShift Would this address your question? (Please consider closing the issue if it does 😃)


The Node gRPC API docs are here. They're for the old library so they're out of date, but they're still mostly right.

Thanks so much for the docs link! For posterity, i've found this page containing some details on the params of the callback method in question.

sampajano commented 9 months ago

Closing for now. Feel free to reopen if you still have questions :)