Skip to content

Commit 4a99afd

Browse files
committed
Don't clean up persistent term
1 parent 0746c94 commit 4a99afd

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/ecto/repo/registry.ex

+12-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ defmodule Ecto.Repo.Registry do
1818
end
1919

2020
def lookup(repo) when is_atom(repo) do
21-
:persistent_term.get(repo, nil) ||
22-
raise "could not lookup Ecto repo #{inspect(repo)} because it was not started or it does not exist"
21+
case Process.whereis(repo) do
22+
nil ->
23+
raise "could not lookup Ecto repo #{inspect(repo)} because it was not started or it does not exist"
24+
25+
_ ->
26+
:persistent_term.get(repo, nil)
27+
end
2328
end
2429

2530
def lookup(pid) when is_pid(pid) do
@@ -45,7 +50,11 @@ defmodule Ecto.Repo.Registry do
4550
@impl true
4651
def handle_info({:DOWN, ref, _type, pid, _reason}, table) do
4752
[{^pid, ^ref, name, _}] = :ets.lookup(table, pid)
48-
name && :persistent_term.erase(name)
53+
# We don't delete from persistent term on purpose. Since the process is
54+
# named, we can assume it does not start dynamically, so it will either
55+
# restart or the amount of memory it uses is negligibla to justify the
56+
# process purging done by persistent_term. If the repo is restarted and
57+
# stores the same metadata, then no purging happens either.
4958
:ets.delete(table, pid)
5059
{:noreply, table}
5160
end

0 commit comments

Comments
 (0)