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:
- My local iex instance
- Running the docker image locally
- curl-ing the request manually on the vps and inside the docker image in vps (I’m using vultr)
- Remote-ing using the release binary and calling the function there
- 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!