Skip to content

Commit

Permalink
Cancel owner_ref and monitor on hold
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jul 1, 2024
1 parent 704845f commit 01abbdc
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/explorer/remote/holder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ defmodule Explorer.Remote.Holder do

@impl true
def handle_call({:hold, ref, pid}, _from, state) do
_ = Process.monitor(pid)
refs = Map.update(state.refs, ref, [pid], &[pid | &1])
pids = Map.update(state.pids, pid, [ref], &[ref | &1])
{:reply, :ok, %{state | refs: refs, pids: pids}}
{:reply, :ok, %{state | refs: refs, pids: pids, owner_ref: nil}}
end

@impl true
Expand All @@ -43,6 +44,8 @@ defmodule Explorer.Remote.Holder do
noreply_or_stop(%{state | pids: pids, refs: refs})
end

# We will only match this clause during initialization,
# the goal is to not leave orphaned processes.
def handle_info({:DOWN, owner_ref, _, _, reason}, %{owner_ref: owner_ref} = state) do
{:stop, reason, state}
end
Expand Down

0 comments on commit 01abbdc

Please sign in to comment.