Skip to content

Commit 4370644

Browse files
authored
Set finite OnceCache timeout for OAuth token exchange and refresh (#1142)
Waiters on Hex.OnceCache shared a hardcoded 5s default timeout while the underlying HTTP call can take up to 15s. Under concurrent private package fetches in :hex_fetcher this caused all but the computing task to time out before the token exchange completed. Use a 60s timeout consistent with Hex.Registry.Server and other HTTP-bound GenServer calls in the codebase. Replace the :infinity timeout in Hex.OAuth with the same bound; the interactive device flow is invoked sequentially from check_and_refresh_auth before parallel fetches begin, so concurrent waiters only ever cover the HTTP refresh path.
1 parent 3e5dd79 commit 4370644

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

lib/hex/oauth.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ defmodule Hex.OAuth do
44
alias Hex.API.OAuth
55

66
@refresh_cache __MODULE__.RefreshCache
7+
@refresh_timeout 60_000
78

89
def start_link(_args) do
910
Hex.OnceCache.start_link(name: @refresh_cache)
@@ -41,11 +42,10 @@ defmodule Hex.OAuth do
4142
{:ok, token_data["access_token"]}
4243
else
4344
# Token expired, use OnceCache to ensure only one refresh/auth happens
44-
# Use infinity timeout because authentication may require user interaction
4545
Hex.OnceCache.fetch(
4646
@refresh_cache,
4747
fn -> do_refresh_or_authenticate(token_data, opts) end,
48-
timeout: :infinity
48+
timeout: @refresh_timeout
4949
)
5050
end
5151
end

lib/hex/repo.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ defmodule Hex.Repo do
22
@moduledoc false
33

44
@exchange_cache __MODULE__.ExchangeCache
5+
@exchange_timeout 60_000
56
@hexpm_url "https://repo.hex.pm"
67
@hexpm_public_key """
78
-----BEGIN PUBLIC KEY-----
@@ -363,7 +364,8 @@ defmodule Hex.Repo do
363364
Hex.OnceCache.fetch_key(
364365
@exchange_cache,
365366
{repo_name, repo_config.auth_key},
366-
fn -> do_exchange_api_key(repo_config, repo_name) end
367+
fn -> do_exchange_api_key(repo_config, repo_name) end,
368+
timeout: @exchange_timeout
367369
)
368370
end
369371
end

0 commit comments

Comments
 (0)