I have a supervision tree, for the sake of simplicity let’s say one supervisor (S
) holding one worker (W
) with :one_for_one
strategy.
Under some circumstances, I need to reinitialize W
and the easiest way to do that is to crash it. I have two different options: Process.exit/2
and/or Supervisor.restart_child/2
:
Process.exit(W, :kill)
and
[{id, _, :worker, _}] = Supervisor.which_children(S)
Supervisor.terminate_child(S, w_id)
Supervisor.restart_child(S, w_id)
Since the latter exists, I suppose it might be of better use, but I cannot realize what would be an advantage of using it. The assumption would be for the strategy :rest_for_one
and many children, the former will restart the whole tail of the workers’ list, while the latter would restart this particular worker only. I cannot find any reasonable documentation on that neither catch this difference in the codebase.
So, the question would be: when using the strategy :one_by_one
does it make any sense to go through terminate
→ restart
loop or Process.exit(pid, :kill)
is sufficient enough?
one_for_rest
strategy it won’t restart subsequent children? If yes, where can I assure it myself? – Ludie