@derekkraan
I have moved the discussion back here because I can’t point this to any specific issue in the library.
I thought that I had a solution above, but what I was actually doing was adding children directly to the Horde.DynamicSupervisor, rather than to the correct place in the tree.
To clarify, this is the full minimal reproducible example:
init_arg = fn name ->
[
name: name,
strategy: :one_for_one,
distribution_strategy: Horde.UniformDistribution,
max_restarts: 100_000,
max_seconds: 1,
members: :auto
]
end
{:ok, root_supervisor} = Horde.DynamicSupervisor.start_link(init_arg.(:root_supervisor))
for num <- 1..10 do
child_supervisor = :"child_supervisor#{num}"
{:ok, _child_supervisor_pid} =
Horde.DynamicSupervisor.start_child(root_supervisor, %{
id: child_supervisor,
start: {Horde.DynamicSupervisor, :start_link, [init_arg.(child_supervisor)]}
})
end
IO.puts("After creation...")
IO.inspect(Horde.DynamicSupervisor.which_children(root_supervisor), pretty: true)
IO.puts("-----------")
for {id, pid, :worker, _startup_module} <-
Horde.DynamicSupervisor.which_children(root_supervisor),
String.starts_with?(Atom.to_string(id), "child_supervisor") do
IO.puts("Trying to terminate worker with id: #{id} and process id: #{inspect(pid)}")
# NOTE: Switched from pid to id
:ok = :supervisor.terminate_child(root_supervisor, id)
:ok = :supervisor.delete_child(root_supervisor, id)
end
IO.puts("After termination...")
IO.inspect(Horde.DynamicSupervisor.which_children(root_supervisor), pretty: true)
IO.puts("-----------")
:done
Here is what After creation...
printout looks like. This is not the way things should be because the workers should not exist at the part of the tree. The only exist because they were added incorrectly by using the supervisor pid and not the name.
After creation...
[
{:child_supervisor10, #PID<0.329.0>, :worker, [Horde.DynamicSupervisor]},
{:child_supervisor9, #PID<0.322.0>, :worker, [Horde.DynamicSupervisor]},
{:child_supervisor8, #PID<0.315.0>, :worker, [Horde.DynamicSupervisor]},
{:child_supervisor7, #PID<0.308.0>, :worker, [Horde.DynamicSupervisor]},
{:child_supervisor6, #PID<0.301.0>, :worker, [Horde.DynamicSupervisor]},
{:child_supervisor5, #PID<0.294.0>, :worker, [Horde.DynamicSupervisor]},
{:child_supervisor4, #PID<0.287.0>, :worker, [Horde.DynamicSupervisor]},
{:child_supervisor3, #PID<0.280.0>, :worker, [Horde.DynamicSupervisor]},
{:child_supervisor2, #PID<0.273.0>, :worker, [Horde.DynamicSupervisor]},
{:child_supervisor1, #PID<0.266.0>, :worker, [Horde.DynamicSupervisor]},
{Horde.NodeListener, #PID<0.265.0>, :worker, [Horde.NodeListener]},
{:root_supervisor_telemetry_poller, #PID<0.264.0>, :worker,
[:telemetry_poller]},
{Horde.SignalShutdown, #PID<0.263.0>, :worker, [GenServer]},
{:"root_supervisor.ProcessesSupervisor", #PID<0.262.0>, :supervisor,
[Horde.ProcessesSupervisor]},
{Horde.DynamicSupervisorImpl, #PID<0.261.0>, :worker,
[Horde.DynamicSupervisorImpl]},
{:"root_supervisor.Crdt", #PID<0.260.0>, :worker, [DeltaCrdt]}
]