peburrows/goth

Too many failed attempts to refresh error

sasikumar87 opened this issue · 6 comments

I am using goth (version 1.3.1) along with google_api_sheets in a phoenix application. After inactive for sometime, I start seeing the following error message in server logs.

[error] GenServer {Goth.Registry, Pattam.Goth} terminating
** (RuntimeError) too many failed attempts to refresh, last error: %RuntimeError{message: "unexpected status 400 from Google\n\n{\"error\":\"invalid_grant\",\"error_description\":\"Invalid JWT: Token must be a short-lived token (60 minutes) and in a reasonable timeframe. Check your iat and exp values in the JWT claim.\"}\n"}
    (goth 1.3.1) lib/goth.ex:248: Goth.handle_retry/2
    (stdlib 4.0.1) gen_server.erl:1120: :gen_server.try_dispatch/4
    (stdlib 4.0.1) gen_server.erl:1197: :gen_server.handle_msg/6
    (stdlib 4.0.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: :refresh

I get this as well. Is the only way to fix this to reboot the app?

There was a similar issue, #113, and the conclusion was we can't do anything about it except wait for the system to self-heal by catching up to NTP and such. By default we're retrying 10 times with an exp delay (1s, 2s, 4s, 8s, ...) which should be plenty of time. But maybe it isn't? You can try bumping the max_retries or even set it to :infinity. Does that help?

This issue can be due to Goth is using System.system_time() , which is affected by time warp .
Changing the option to the mutli_time_warp mode may help to mitigate this issue.
However, since JWT tokens require the real-world time, shouldn't goth use System.os_time() instead here?
https://github.com/peburrows/goth/blob/master/lib/goth/client.ex#L160

Oh System.system_time would never by default self heal (so to speak)? A patch changing to use os_time would be appreciated.

aspala commented

We encounter the same problem.

Should be fixed by #158, it was just released in v1.4.1.