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
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 the...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> somethi...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
For example for a current url like
http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2,
I would like to get:
...
New
Hi,
is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
Hello, how can I check the Phoenix version ?
Thanks !
New
In templates/appointment/index.html.eex:
<%= for appointment <- @appointments do %>
<tr>
<td><%= appoi...
New
I have a super simple question about elixir - how would I take a file like this
foo
bar
baz
and output a new file that enumerates th...
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)?
Would
mix ecto.rollback -v 200809061...
New
Other popular topics
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar.
I p...
New
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something…
Haskell reminds me of Java, and e...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









