david_ex

david_ex

Hi,

I’m writing my own toy implementation of a worker pool manager for learning purposes.

I do have one remaining issue (or at least only one I’ve identified :stuck_out_tongue:): when creating a new pool, a dynamic supervisor is used to start another (normal) supervisor that sits above all processes related to that pool. If I kill this supervisor, it doesn’t get restarted. Instead I get an error like

08:39:40.848 [error] GenServer #PID<0.4648.0> terminating
** (stop) killed
Last message: {:EXIT, #PID<0.4647.0>, :killed}
State: %PoolToy.PoolMan.State{idle_overflow: [], monitors: :"monitors_#PID<0.4648.0>", overflow: 0, overflow_max: 0, overflow_ttl: 0, overflow_ttl_timer: nil, size: 2, spec: PoolToy.Worker, sup: #PID<0.4647.0>, waiting: {[], []}, worker_sup: #PID<0.4649.0>, workers: [#PID<0.4652.0>, #PID<0.4651.0>]}
 
08:39:40.849 [error] GenServer #PID<0.4649.0> terminating
** (stop) killed
Last message: {:EXIT, #PID<0.4647.0>, :killed}
State: %DynamicSupervisor{args: [], children: %{#PID<0.4651.0> => {{PoolToy.Worker, :start_link, :undefined}, :temporary, 5000, :worker, [PoolToy.Worker]}, #PID<0.4652.0> => {{PoolToy.Worker, :start_link, :undefined}, :temporary, 5000, :worker, [PoolToy.Worker]}}, dynamic: 2, extra_arguments: [], max_children: :infinity, max_restarts: 3, max_seconds: 5, mod: PoolToy.WorkerSup, name: {#PID<0.4649.0>, PoolToy.WorkerSup}, restarts: [], strategy: :one_for_one}

I don’t know what code would be relevant to include here, so I’ve pushed the current state to github: GitHub - davidsulc/pool_toy: A toy worker pool implementation aiming to teach about process supervision trees · GitHub You can download the code from https://github.com/davidsulc/pool_toy/archive/master.zip

Here are the steps to reproduce the issue (within the pool_toy directory):

# start the app
iex -S mix

# start a pool named :pool_a with 2 workers
iex> PoolToy.start_pool(PoolToy.Worker, 2, name: :pool_a)

# start the observer
iex> :observer.start

Within the applications tab of the observer, right click on the direct child of the named Elixir.PoolToy.PoolsSup process (which will have no name, just a pid) and kill it. I would expect the process to get restarted by the Elixir.PoolToy.PoolsSup dynamic supervisor but that’s not the case. Why?

Showing Posts 1 to 3

minhajuddin

minhajuddin

Your restart strategy is :temporary which means it won’t be restarted even if it fails. Take a look at this: Supervisor.Spec — Elixir v1.20.2 to know which restart strategy you should use.

kokolegorille

kokolegorille

The dynamic supervisor should be as dumb as possible.

If You are still following poolboy example, there is a GenServer that use a single_one_for_one supervisor for starting temporary worker. This GenServer is linked to those temporary workers, and thus knows when they are dying. It can take appropriate measure…

With the Dynamic supervisor scenario, it would be a GenServer, starting workers processes, through a dynamic supervisor… and linking each worker process.

Workers are temporary in poolboy, because they are not restarted from the supervisor, even if in your case workers are also supervisors

david_ex

david_ex OP

Having cleared my head, @minhajuddin put me on the right track: I got confused between the restart strategy given to the use macro and the restart strategy given to the init function of the Supervisor/DynamicSupervisor modules…

Of course, the value given to use does NOT determine how/if children are restarted, but determines the module’s own restart strategy as it’s used to create the module’s child spec. The restart value given to init on the other hand determines how/if the supervisor’s children are restarted. Confusing the two was the cause of my downfall :stuck_out_tongue:

Thanks @minhajuddin and @kokolegorille for your help!

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews