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?

Where Next?

Popular in Questions Top

sen
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
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
tduccuong
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
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
jaysoifer
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
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
lanycrost
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

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
baxterw3b
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
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New
dogweather
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
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

We're in Beta

About us Mission Statement