Skip to content

Commit

Permalink
Fix recursive Hex.State call during application start (#982)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmj authored Feb 6, 2023
1 parent daccf2c commit 018ba1f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/hex/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,15 @@ defmodule Hex.Repo do
Map.new(repos, fn {name, repo} ->
case split_repo_name(name) do
[source, organization] ->
source = get_repo(source)
state_pid = Process.whereis(Hex.State)

source =
if state_pid && state_pid != self() do
get_repo(source)
else
Map.fetch!(repos, source)
end

repo = default_organization(repo, source, organization)
{name, repo}

Expand Down
30 changes: 30 additions & 0 deletions test/hex/repo_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,34 @@ defmodule Hex.RepoTest do
url: "http://example.com/repos/acme"
}} = Hex.Repo.fetch_repo("hexpm:acme")
end

if Version.match?(System.version(), "< 1.6.0") do
@tag :skip
end

test "update_organizations/1 without Hex.State" do
:ok = Supervisor.terminate_child(Hex.Supervisor, Hex.State)
:ok = Supervisor.delete_child(Hex.Supervisor, Hex.State)

repos = %{
"hexpm" => %{
url: "http://example.com",
public_key: "public",
auth_key: "auth",
trusted: true
},
"hexpm:acme" => %{}
}

assert %{
"hexpm:acme" => %{
auth_key: "auth",
public_key: "public",
trusted: true,
url: "http://example.com/repos/acme"
}
} = Hex.Repo.update_organizations(repos)
after
{:ok, _} = Supervisor.start_child(Hex.Supervisor, Hex.State)
end
end

0 comments on commit 018ba1f

Please sign in to comment.