I’m using Guardian to handle JWT tokens, and I noticed that after a given amount of time, the client app would not be able to refresh an refresh token into an access token. The request to refresh it would succeed, but the client app would say that the newly generated token was expired, which sure enough it was.
Digging into the Guardian source code, the timestamp is generated with System.system_time(:second)
, not DateTime.utc_now() |> DateTime.to_unix()
, and sure enough, when I try both of those, they are different, by 97 minutes(my access token TTL is 60 minutes).
According to https://www.unixtimestamp.com/, the timestamp right now is roughly:
1685035696
iex(77)> System.system_time(:second)
1685029895
iex(78)> DateTime.to_unix(DateTime.utc_now())
1685035749
iex(79)> 1685035749 - 1685029895
5854
So my System.system_time
is nearly 6000 seconds, ~100 minutes off the real time. I’ll admit I don’t have the clearest understanding of time warp, but this seems to happen consistently after about 6-8 hours of running the server. I have not changed timezone. I have not had daylight savings or a clock change. Any idea what could be causing this?
EDIT: In a new IEx console, they are equal again:
iex(1)> DateTime.to_unix(DateTime.utc_now()) - System.system_time(:second)
0
On the dev server that’s been running for 12 hours:
iex(96)> DateTime.to_unix(DateTime.utc_now()) - System.system_time(:second)
5831
Here are the specifics of the current uptime:
iex(107)> :erlang.statistics(:wall_clock)
{31386845, 9639}
iex(108)> :erlang.statistics(:runtime)
{471130, 23}
.tool-versions
elixir 1.14.4-otp-25
erlang 25.3