Home How do supervisors not crash when one of the children processes crashes
Post
Cancel

How do supervisors not crash when one of the children processes crashes

When you start an Agent or GenServer they will be linked to the current process and the current process will crash if the linked Agent or GenServer crashes. However Supervisors do not crash even if the child processes that are linked to the supervisor crash. Well, the answer is obvious.

Because Supervisors trap the exit signals.source code

Assuming that you’ve at least one child spec in your children list below, you can also confirm that doing:

1
2
3
4
{:ok, supervisor} = Supervisor.start_link(children, strategy: :one_for_one)

Process.info(supervisor, :trap_exit)
# => {:trap_exit, true}
This post is licensed under CC BY 4.0 by the author.