mickel8

mickel8

Membrane Core Team

Elixir-grpc can't receive stream response. Unexpected when waiting for headers-

Hi, I am trying to stream data to Google Cloud Speech-To-Text and receive a response but almost every request ends up with an error

%GRPC.RPCError{status: 2, message: "unexpected when waiting for headers: {:data, <<0, 0, 0, 0, 62, 42, 4, 50, 2, 8, 21, 50, 54, 10, 34, 10, 27, 32, 109, 97, 121, 98, 101, 32, 109, 97, 121, 98, 101, 32, 115, 111, 109, 101, 116, 104, 105, 110, 103, 32, 101, 108, 115, 101, 21, 57, 172, 96, ...>>}"}

or

%GRPC.RPCError{status: 2, message: "unexpected when waiting for headers: {:trailers, [{\"grpc-status\", \"0\"}, {\"content-disposition\", \"attachment\"}, {\"x-goog-ext-27651507-bin\", \"DbOLmjwVzczMPQ==\"}, {\"x-goog-ext-9650773-bin\", \"DUh68T8=\"}]}"}

The flow is more or less

    GRPC.Stub.connect(@service_url,
      cred: cred,
      adapter_opts: adapter_opts,
      adapter: GRPC.Client.Adapters.Gun,
      headers: %{
        "Authorization" => authorization_header(),
        "Content-Type" => "application/grpc"
      }
    )

    GRPC.Stub.send_request(stream, request)
    GRPC.Stub.recv(stream, timeout: timeout)

When I changed the adapter from Gun to Mint, the library crashes

[error] GenServer #PID<0.16840.0> terminating
** (ArgumentError) request with request reference #Reference<0.200553127.2209087489.150902> was not found
    (mint 1.4.2) lib/mint/http2.ex:765: Mint.HTTP2.get_window_size/2
    (grpc 0.6.0) lib/grpc/client/adapters/mint/connection_process/connection_process.ex:347: GRPC.Client.Adapters.Mint.ConnectionProcess.get_window_size/2
    (grpc 0.6.0) lib/grpc/client/adapters/mint/connection_process/connection_process.ex:205: GRPC.Client.Adapters.Mint.ConnectionProcess.handle_continue/2
    (stdlib 5.1.1) gen_server.erl:1067: :gen_server.try_handle_continue/3
    (stdlib 5.1.1) gen_server.erl:977: :gen_server.loop/7
    (stdlib 5.1.1) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
Last message: {:continue, :process_request_stream_queue}

First Post! Switch mode

mickel8

mickel8

Membrane Core Team

Okay I found the problem

That’s because of my default handle_info callback which drops messages. Gun by default sends messages to a process that spawns it. Because it’s my gen server who calls grpc functions, it’s also my gen server who spawns gun

if anything from gun comes to my gen server before I call GRPC.Stub.recv (so gun:await under the hood), this message will be dropped by my handle_info

if messages come after I call GRPC.Stub.recv, everything is okay as Stub.recv is blocking and goes through the whole mailbox

Looks like GRPC.Stub.recv can’t be used in GenServers :thinking:

Where Next?

Trending in Questions Top

jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
saveman71
Hello ! We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement