gavid
Horde.DynamicSupervisor.terminate_child is not working!
Horde.DynamicSupervisor.terminate_child seems to be unable to find the children of the Horde.DynamicSupervisor, even when they are clearly defined.
Here is a 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)}")
:ok = Horde.DynamicSupervisor.terminate_child(root_supervisor, pid)
end
IO.puts("After termination...")
IO.inspect(Horde.DynamicSupervisor.which_children(root_supervisor), pretty: true)
IO.puts("-----------")
:done
Marked As Solved
gavid
Also Liked
derekkraan
Hi @gavid ,
It took me a minute to figure out what was going on here. The short story is, you should use the name of your Horde.DynamicSupervisor, not its pid. The pid you get back is only suitable for use in the supervision tree, and it is not meant to be used in any of the other functions in Horde.DynamicSupervisor.
See below the modified version of your test script:
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))
root_supervisor = :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)}")
:ok = Horde.DynamicSupervisor.terminate_child(root_supervisor, pid)
end
IO.puts("After termination...")
IO.inspect(Horde.DynamicSupervisor.which_children(root_supervisor), pretty: true)
IO.puts("-----------")
:done
1
Popular in Questions
can someone please explain to me how Enum.reduce works with maps
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I'm writing a test for one of t...
New
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Other popular topics
Hi! May someone helps me, please!
I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
Manning 2016 Halloween weekend sale via Deal of the Day
Friday, October 28 - Half off all MEAPs - code WM102816LT
Saturday, October 29 ...
New
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode.
The solution seems to be, in a hyphena...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Hey :wave:t3: Elixir community,
I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New







