Process calling http request get killed without reason

Hello, so I have a chatbot written in elixir with plug and I have a problem. There is few functions where it do an http requests and it might take few seconds. My problem is that the requests seems to be stuck as any function after the requests didn’t get called.

One of the function in question is in https://github.com/ridho9/hibiki-elixir/blob/cffcfd3e18d02072ece8d0d6c75b0427fe2df8ec/apps/hibiki/lib/hibiki/lib/translate.ex#L2.

def translate(query) do
    url = @url <> "/translate/tl"

    http_config = [
      hackney: [pool: :tl],
      recv_timeout: 30_000,
      timeout: 30_000
    ]

    with {:ok, body} <- Jason.encode(%{"src" => query}),
         {:ok, %HTTPoison.Response{body: body}} <- HTTPoison.post(url, body, [], http_config),
         {:ok, result} <- Jason.decode(body) do
      {:ok, result}
    end
  end

Any attempts of IO.inspect the with block result never came and there is no error log.

I tried to trace the function with rexbug and this is what I get

iex(hibiki_elixir@1e5696df6a2d)3> Rexbug.start "Hibiki.Translate.translate/_ :: return;stack"
{310, 1}

# 10:03:45 #PID<0.3096.0> :erlang.apply/2
# Hibiki.Translate.translate("asd")
#   Hibiki.Command.Translate.handle/2
#   Teitoku.HandleableEvent.Hibiki.Event.Command.handle/2
#   Teitoku.Event.process_event/3
#   Task.Supervised.invoke_mfa/2
#   Task.Supervised.reply/5
#   :proc_lib.init_p_do_apply/3

# 10:03:46 #PID<0.3096.0> (:dead)
# Hibiki.Translate.translate/1 -> {:exit, :shutdown}
redbug done, timeout - 1

There it said that the process is dead with {:exit, :shutdown} but I have no idea what happened as there is no error log.

The frustrating part is that this works just fine on:

  1. My local iex instance
  2. Running the docker image locally
  3. curl-ing the request manually on the vps and inside the docker image in vps (I’m using vultr)
  4. Remote-ing using the release binary and calling the function there
  5. Sometimes it works on the second invocations, sometimes it doesn’t

I’ve also tried using tesla with httpc, hackney, and mint adapter but it doesn’t help.

Could anyone help me? Because I really love elixir and I don’t want to force to change just because of this really obscure and weird problem. Thanks for reading!

:wave:

Note that this rexbug command only traces your own module, not http request in httpoison.

As for your problem, maybe the client (Line) drops the connection before the response from DeepL arrives? It would explain {:exit, :shutdown} and why no functions after the HTTP request were called.

{:exit, :shutdown} means the process that called Hibiki.Translate.translate has exitted, it doesn’t necessarily mean it failed or that it was killed, since then the exit reason (:shutdown) would’ve been different – :killed.

1 Like

Thanks for replying! Do you have any idea of how I could try to check for the possibilities that the connection is dropped? In my desperate mind I was thinking to check the packets using wireshark but I have no knowlegde in that.

After your post I tried to just isolate calling the command handler using Task.start since I doesn’t really need to have the request’s result and it’s working fine! Thanks! I guess it makes sense since the only time the request is failing is while it is inside a plug process. I’m still curious as what caused the process to be killed since there’s just no reason.