elixir-grpc / grpc

An Elixir implementation of gRPC
https://hex.pm/packages/grpc
Apache License 2.0
1.4k stars 214 forks source link

Getting 'shouldn't finish when getting headers, status : 13' with the latest release #48

Closed shiroyasha closed 6 years ago

shiroyasha commented 6 years ago

I've tried to update to the latest release, but I am getting the following error when I try to trigger a call from from the client.

** (MatchError) no match of right hand side value: {:error, %GRPC.RPCError{message: "shouldn't finish when getting headers", status: 13}}

Let me know if I can help with debugging.

These are the deps on my project:

{:phoenix, github: "phoenixframework/phoenix"},
{:phoenix_html, github: "phoenixframework/phoenix_html"},
{:poison, "~> 3.1"},
{:gettext, "~> 0.11"},
{:cowboy, "~> 2.2"},
{:protobuf, "~> 0.5"},
{:grpc, github: "tony612/grpc-elixir"},
tony612 commented 6 years ago

Could you describe what your client and server do? This error occurs when the first header sent by the server contains a flag END_STREAM, which means the stream is end. I thought this should not happen in a normal gRPC call, so I let it return an error in this situation. But if it's reasonable for your scene, I can change that. Like below questions:

  1. What your rpc calls type? (Unary, Client streaming, Server streaming, Bi-streaming)
  2. Is there error log on the server side?
  3. What type of data do your rpc functions return on the server side?(The stream struct, your reply struct..)
  4. If you use streaming, what do you send to the peer? Like reply, headers(metadata). And what's the order?
  5. In the functions you call to send messages(in 4), do you use the new stream as the next function's argument?

If possible, you can send me an example of your code. It'll be better if the code can reproduce the problem.

shiroyasha commented 6 years ago

@tony612 thanks for the feedback.

This seems to happen only when I do a simple request_response call to a Ruby based GRCP server. Interestingly, when I do Elixir Client -> Elixir Server everything works, but with Elixir Client -> Ruby Server I get the above error.

I'll try to reproduce this edge case for a simple hello world GRPC call and share the code examples.

shiroyasha commented 6 years ago

@tony612 I've prepared a hello world example communication that demonstrates this issue.

https://github.com/renderedtext/elixir-ruby-failure-example-grpc

The issue seems to be connected to timing. If the server takes more than 100ms to respond, the original error appears.

I hope this helps. Please let me know if I can help out in any other way. 🙇

shiroyasha commented 6 years ago

Some updates:

I've added some debugging steps to the gun await method https://github.com/tony612/grpc-elixir/pull/49.

When I run the code, I got the following messages:

{:response, :fin, 200,
 [{"content-type", "application/grpc"}, {"grpc-status", "4"},
  {"grpc-message", "Deadline Exceeded"}]}
{:error,
 %GRPC.RPCError{message: "shouldn't finish when getting headers", status: 13}}
shiroyasha commented 6 years ago

By digging a bit deeper, I've found the following difference between the Ruby and Elixir clients:

When a Ruby client makes the call, the deadline is set to: 1970-01-01 00:59:59 +0100. When the Elixir client makes the call, the deadline is set to: 2018-03-22 20:49:30 +0100 (current second).

The Ruby GRPC client sets the deadline to INFINITE_FUTURE: https://github.com/grpc/grpc/blob/7e24da469c2a931ee988d35bf99b9e47e8fa5940/src/ruby/lib/grpc/generic/client_stub.rb#L29.

tony612 commented 6 years ago

Thank you. This is very helpful. I’ll fix it ASAP. On Fri, 23 Mar 2018 at 04:26 Igor Šarčević notifications@github.com wrote:

By digging a bit deeper, I've found the following difference between the Ruby and Elixir clients:

When a Ruby client makes the call, the deadline is set to: 1970-01-01 00:59:59 +0100. When the Elixir client makes the call, the deadline is set to: 2018-03-22 20:49:30 +0100 (current second).

The Ruby GRPC client sets the deadline to INFINITE_FUTURE: https://github.com/grpc/grpc/blob/7e24da469c2a931ee988d35bf99b9e47e8fa5940/src/ruby/lib/grpc/generic/client_stub.rb#L29 .

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/tony612/grpc-elixir/issues/48#issuecomment-375445963, or mute the thread https://github.com/notifications/unsubscribe-auth/ABMhG5kooY2CJopbfF5vsMetmZboNjIPks5thAj7gaJpZM4S1OEA .

tony612 commented 6 years ago

It's on master now.

tony612 commented 6 years ago

I've released 0.3.0-alpha.1 to fix this.