Skip to content

Commit 23633f7

Browse files
committed
Use IEx.Broker.shell to find nodes instead of group leader, closes #15092
1 parent ab7c019 commit 23633f7

1 file changed

Lines changed: 24 additions & 19 deletions

File tree

lib/iex/lib/iex/broker.ex

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,27 @@ defmodule IEx.Broker do
1414
## Shell API
1515

1616
@doc """
17-
Finds the evaluator and server running inside `:user_drv`, on this node exclusively.
17+
Finds the `:user_drv` backed shell on this node.
18+
19+
We don't use `:shell.whereis/0` because that uses the current group leader
20+
and we want to find one regardless of the group leader.
21+
"""
22+
def shell() do
23+
case :user_drv.whereis_group() do
24+
:undefined ->
25+
nil
26+
27+
pid ->
28+
{:dictionary, dictionary} = Process.info(pid, :dictionary)
29+
dictionary[:shell]
30+
end
31+
end
32+
33+
@doc """
34+
Finds the evaluator and server running on this node exclusively.
1835
"""
1936
@spec evaluator(shell()) :: {evaluator :: pid, server :: pid} | nil
20-
def evaluator(pid \\ :shell.whereis()) do
37+
def evaluator(pid \\ shell()) do
2138
if pid do
2239
{:dictionary, dictionary} = Process.info(pid, :dictionary)
2340
{dictionary[:evaluator], pid}
@@ -148,23 +165,11 @@ defmodule IEx.Broker do
148165
end
149166

150167
defp servers(state) do
151-
if pid = local_or_remote_shell() do
152-
[{Process.monitor(pid), pid} | Enum.to_list(state.servers)]
153-
else
154-
Enum.to_list(state.servers)
155-
end
156-
end
168+
shells =
169+
for node <- [node() | Node.list()],
170+
pid = :erpc.call(node, IEx.Broker, :shell, []),
171+
do: {Process.monitor(pid), pid}
157172

158-
defp local_or_remote_shell() do
159-
Enum.find_value([node() | Node.list()], fn node ->
160-
try do
161-
case :erpc.call(node, :shell, :whereis, []) do
162-
pid when is_pid(pid) -> pid
163-
:undefined -> nil
164-
end
165-
catch
166-
_, _ -> nil
167-
end
168-
end)
173+
shells ++ Enum.to_list(state.servers)
169174
end
170175
end

0 commit comments

Comments
 (0)