visciang / telegram

Telegram library for the Elixir language
MIT License
204 stars 27 forks source link

Telegram.Poller crashing on timeout #175

Closed ultrakorne closed 2 weeks ago

ultrakorne commented 2 weeks ago

I am not very familiar with the telegram api, so apologies if i get it wrong.

whenever connection goes in timeout with the Poller we get

** (RuntimeError) Telegram.Api.request 'getUpdates' error: {:error, :timeout}
    (telegram 1.2.2) lib/poller.ex:142: Telegram.Poller.Task.wait_updates/1
    (telegram 1.2.2) lib/poller.ex:126: Telegram.Poller.Task.loop/1

should'nt we do something like

 case Telegram.Api.request(context.token, "getUpdates", opts) do
      {:ok, updates} ->
        updates

      {:error, :timeout} ->
        Logger.error("Telegram.Api.request 'getUpdates' timed out. Retrying...")
        wait_updates(context)

      error ->
        # coveralls-ignore-start
        raise "Telegram.Api.request 'getUpdates' error: #{inspect(error)}"
        # coveralls-ignore-stop
    end
visciang commented 2 weeks ago

Thank you for the reporting @ultrakorne.

Release 1.2.3 includes the fix.

Please check 0838ff0d3729f496a8cba28fcce7dce340577d89 , I have included a log about a possible misconfiguration. Maybe you are hitting the same.

ultrakorne commented 2 weeks ago

thank for the quick reply, will update to 1.2.3!

i was seeing the error consistently, but my conf is adapter Tesla.Adapter.Finch, name: __MODULE__, receive_timeout: 40_000 which should be strictly greater than the default 30s timeout

visciang commented 2 weeks ago

Could you check what is the timeout you get with that config? Maybe check also what happens with request_timeout: 40_000 instead of receive_timeout: 40_000.

I don't get any timeout with the finch config you can see here https://github.com/visciang/telegram/commit/0667e3b28a5bab7f7b354dec299ca66bbe755b41

ultrakorne commented 2 weeks ago

i updated to 1.2.3, I tried request_timeout and tried even a longer timeout of 140_000. and with config :telegram, :get_updates_poll_timeout_s, 20

I am basically running your example Counter from your telegram example repo, just with a Poller instead of the webhook.

I will try to run the sleepbot example to see if that works for me.

visciang commented 2 weeks ago

@ultrakorne I've reproduced the issue.

It should be an issue with the tesla finch adapter, options are not passed down to finch from the adapter macro. I'm going to open an issue there.

BTW: if you pass the finc options via config it works, see 3b6f0280231286da906c33ede1eac707da0a22f3. Give it a try!

ultrakorne commented 2 weeks ago

@visciang thank you, this actually fixes the issue.

Thanks for helping out. I just started learning elixir so my debugging capabilities are very limited