sezaru

sezaru

How to kill supervisor when linked process is killed?

Hello!

In my application, I have two apps called market_manager and candle_manager.

In app candle_manager, I have this tree structure:


In app market_manager, I have this one:
02
MarketManager.ManagersSupervisor is a dynamic supervisor that can start managers. When I start one Manager, I get this:
03
Also, the manager that I started will start a new child in CandleManager.Bitfinex.RealtimeSupervisor called CandleManager.Bitfinex.Realtime.Supervisor:

CandleManager.Bitfinex.Realtime.Supervisor is started with :temporary restart, and its PID is linked to the Manager one via Process.link.

So, for example, if Manager has PID <0.612.0> and CandleManager.Bitfinex.Realtime.Supervisor PID <0.613.0> there will be a link between these two (I can confirm via :observer).

Now, if I go to :observer and kill CandleManager.Bitfinex.Realtime.Supervisor, then Manager will receive the exit message and kill itself too (as expected).

But, if I kill the Manager instead, CandleManager.Bitfinex.Realtime.Supervisor is not killed and Manager will fail to restart since it will try to start a new CandleManager.Bitfinex.Realtime.Supervisor and fail with :already_started error.

So, my question is, does Process.link work correctly with Supervisors? How can I make CandleManager.Bitfinex.Realtime.Supervisor kill itself when Manager is killed?

Just for completeness, here is CandleManager.Bitfinex.Realtime.Supervisor code, it doesn’t have anything fancy that I can see breaking the Process.link logic.

defmodule CandleManager.Bitfinex.Realtime.Supervisor do
  use Supervisor

  alias CandleManager.Bitfinex.Realtime

  require Logger
  def start_link(args) do
    Supervisor.start_link(__MODULE__, args, name: __MODULE__)
  end

  @impl Supervisor
  def init([market_manager_pid: _pid] = args) do
    childrens = [
      {Realtime.Websocket.Server, []},
      {Realtime.Manager.Server, []},
      {Realtime.TradeToCandle.Server, []},
      {Realtime.TradeDiscarder.Server, args}
    ]

    Supervisor.init(childrens, strategy: :one_for_all, max_restarts: 0)
  end
end

Thanks!

Most Liked

NobbZ

NobbZ

Have you consider the one_for_all strategy?

https://hexdocs.pm/elixir/Supervisor.html#module-strategies

Where Next?

Popular in Questions Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
ashish173
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
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New
siddhant3030
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

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
Harrisonl
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
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
ashish173
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
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
siddhant3030
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

We're in Beta

About us Mission Statement