gavid
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
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
Hello,
I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
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
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex











Showing Posts 1 to 10- Show Best Posts
- Show All Posts (oldest first)
- Show All Posts (newest first)
gavid
@derekkraan
You have made an awesome library which we believe is capable of meeting our distributed Supervision needs.
Please can you help me understand this issue so that I can finish implementing it within our code base?
derekkraan
Hi @gavid ,
It took me a minute to figure out what was going on here. The short story is, you should use the
nameof your Horde.DynamicSupervisor, not itspid. 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:
gavid
Thanks for getting back to me Derek!
Okay. So this is different from the DynamicSupervisor API, which allows you to use pids for supervisors and children. E.g:
For Horde.DynamicSupervisor, what about the case when we don’t have
:root_supervisoras a name on the local node?In the real-life version of this, I register the
:root_supervisorunder my instantiation of the Horde.Registry, and then use its pid (retrieved from the registry as needed) to refer to it across the cluster.gavid
If I run the first part of the code (Up to “After creation…”) on node 1, here is what I see:
And then I try to terminate a child using the supervisor name, it works:
But, the other node can’t see the supervisor at all:
Hence the desire to use pids and not names
derekkraan
What is your use case that you need dynamic dynamic supervisors?
derekkraan
Regardless, the reason we can’t make it work this way is because Horde.DynamicSupervisor has its own mini supervision tree. The top of that tree has to be returned from
start_link/3, so that it can fit neatly into your application’s supervision tree. The process that is receiving messages when you callHorde.DynamicSupervisor.which_children/1for example is a child of this supervisor.I would like to find a way to make these both the same, but I currently don’t know how that would work or even if it is workable.
gavid
We have a meta-programming based IDE that allows human and AI agents to create application flows and have them compile to Elixir under the hood. Among the things that these flows can do is start different kinds of Supervisors.
The concept works well, and it has been used in production for a few years.
The challenge now is that we want to be able to support multiple nodes in a cluster with full location transparency.
gavid
@derekkraan
FYI, found a work-around. I used :supervisor.delete_child (supervisor — OTP 29.0.2 (stdlib 8.0.1)) followed by :supervisor.terminate_child (supervisor — OTP 29.0.2 (stdlib 8.0.1)). This works, even on Horde.Supervsior. Both functions accept a pid for the first argument (i.e. to refer to the supervisor), and an
idto refer to the child.gavid
To edit the original script accordingly:
derekkraan
I do not think this is doing what you think it is doing. I believe you are starting your child processes as children of a regular (non-distributed) supervisor. If your node goes down, for example, then your processes will not be restarted on another node.
If you don’t need this behaviour, then I would suggest that you probably don’t need Horde, and can get away with using Elixir’s built-in supervisor and registry.
Hope this helps.