Skip to content

Commit

Permalink
Don't clean up persistent term
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Nov 9, 2024
1 parent 0746c94 commit 4a99afd
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/ecto/repo/registry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ defmodule Ecto.Repo.Registry do
end

def lookup(repo) when is_atom(repo) do
:persistent_term.get(repo, nil) ||
raise "could not lookup Ecto repo #{inspect(repo)} because it was not started or it does not exist"
case Process.whereis(repo) do
nil ->
raise "could not lookup Ecto repo #{inspect(repo)} because it was not started or it does not exist"

_ ->
:persistent_term.get(repo, nil)
end
end

def lookup(pid) when is_pid(pid) do
Expand All @@ -45,7 +50,11 @@ defmodule Ecto.Repo.Registry do
@impl true
def handle_info({:DOWN, ref, _type, pid, _reason}, table) do
[{^pid, ^ref, name, _}] = :ets.lookup(table, pid)

Check warning on line 52 in lib/ecto/repo/registry.ex

View workflow job for this annotation

GitHub Actions / unit test (1.11.4, 21.3.8.24)

variable "name" is unused (if the variable is not meant to be used, prefix it with an underscore)
name && :persistent_term.erase(name)
# We don't delete from persistent term on purpose. Since the process is
# named, we can assume it does not start dynamically, so it will either
# restart or the amount of memory it uses is negligibla to justify the
# process purging done by persistent_term. If the repo is restarted and
# stores the same metadata, then no purging happens either.
:ets.delete(table, pid)
{:noreply, table}
end
Expand Down

0 comments on commit 4a99afd

Please sign in to comment.