Genserver crash entire application

HI people, i am beginner in this language, and i m studing now the fault tolerance approachs…
I create a application by Mix,

well, i forced a error in method passing
iex -S mix
> Sup.Accumulator.add(1)
> Sup.Accumulator.add(“dez”)

Ok, the GenServer crash and are reloaded after…

But, if i do many times, fast the application crash…

Is it a normal Behavior ? if a genserver crash frequently, the entire applications is down ?

If not, what im making wrong ?

Thanks

This is entire normal behaviour. It can be configured slightly by modifying the restart intensity and interval but normally if a GenServer crashes too many times in a short interval the supervisor supervising the GenServer will be restarted as well. If things keep on crashing the error will “bubble-up” to the next supervising entity until it crashes the entire VM.

This is called a supervision tree and is used to decide how crashes in an application should be handled. The supervisor can in turn have different strategies on how to restart its children. For example, restart all if any one crashes, or only restart the one particular child that crashed.

http://learnyousomeerlang.com/supervisors

Explains it well. It is using erlang but the same concepts applies to elixir as well.

The concepts of supervision trees takes a while to get used to but they are very powerful in how you handle errors and design your application.

Also, some parts of your application may not be equally suited to crashing the supervision trees. These are normally things communicating with the outside world. You may not for example wan’t you application to crash just because you can’t connect to your external database. The normal case here is write the external interfaces more defensively to avoid crases.

4 Likes