Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/elsa/dynamic_process_manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,14 @@ defmodule Elsa.DynamicProcessManager do
end

defp whereis({:via, registry_module, lookup}) do
registry_module.whereis_name(lookup)
case registry_module.whereis_name(lookup) do
:undefined -> nil
pid -> pid
end

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this bit just so that we'd be consistent within this module, instead of having a mixture of ":undefined" and "nil" for not-found processes.

end

defp wait_for(name) do
case Process.whereis(name) do
case whereis(name) do

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just a fairly clear oversight from the original library -- there's a whereis override that handles ":via" lookups, but it was only being used on startup and was forgotten about here.

nil ->
Process.sleep(200)
wait_for(name)
Expand Down
17 changes: 15 additions & 2 deletions lib/elsa/elsa_registry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,21 @@ defmodule Elsa.ElsaRegistry do
@spec whereis_name({atom(), term()}) :: pid() | :undefined
def whereis_name({registry, key}) do
case :ets.lookup(registry, key) do
[{^key, pid}] -> pid
[] -> :undefined
[{^key, pid}] ->
# The process was found in the registry, but an additional Process.alive? check is still necessary.
# Otherwise there's a window of opportunity between when the process dies,
# and when the registry receives the EXIT message to remove the key from ETS.
if Process.alive?(pid) do
# Process was found in the registry and is alive
pid
else
# Process was found in the registry, but it's dead
:undefined
end

[] ->
# Process was not found in the registry
:undefined
end
end

Expand Down
Loading