Skip to content

Commit

Permalink
Call off start_child when the group leader terminates (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanklosko authored Sep 19, 2024
1 parent 54ba485 commit a085ab8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/kino/terminator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ defmodule Kino.Terminator do
end

if pid do
terminator = cross_node_name()

Kino.Bridge.reference_object(pid, parent)
Kino.Bridge.monitor_object(pid, cross_node_name(), {:terminate, pid}, ack?: true)

with {:request_error, :terminated} <-
Kino.Bridge.monitor_object(pid, terminator, {:terminate, pid}, ack?: true) do
# If the group leader terminated, it is not going to monitor
# the process as we expect, so we terminate it immediately
send(terminator, {:terminate, pid})
end
end

resp
Expand Down Expand Up @@ -75,6 +83,11 @@ defmodule Kino.Terminator do
{:noreply, Map.delete(state, pid)}
end

def handle_info({:terminate, pid}, state) do
DynamicSupervisor.terminate_child(Kino.DynamicSupervisor, pid)
{:noreply, Map.delete(state, pid)}
end

@impl true
def handle_info({:DOWN, _, _, pid, reason}, state) do
{parent, state} = Map.pop(state, pid)
Expand Down

0 comments on commit a085ab8

Please sign in to comment.