2 min read

How to crash the BEAM using a one liner

As you probably know the Elixir runtime (i.e. the BEAM or the Erlang VM) is said to be fault tolerant. Usually if you make developer mistakes, get some unexpected errors, or maybe even expected errors the "crash" is isolated and only the process you are executing the code on crashes:

Of course if we link to the process crashing, our main process could also crash:

Although the BEAM seems indestructible, the truth is, it also has its limits:

From: http://erlang.org/documentation/doc-5.8.4/doc/efficiency_guide/advanced.html

As we can see there are some system limits to our first class citizen types (like processes, atom, tuples, etc.), but how are they applied ?

Let us take the atoms limit, and try to go over the limit and see what happens. To make this easy, we will generate atoms from numbers:

We are still below the limit, so nothing happened so far, but let us add 100k more atoms and observe what happens:

Oooops... Seems like we crashed the BEAM.

Lessons learnt from this pill:

  1. BEAM usually isolates crashes to processes
  2. We need to carefully consider when to spawn with link (there is also the possiblity to monitor the process without link)
  3. BEAM can be crashed using the system limits (these limits by default are set to a soft limit only, if we think our system can go over them, these limits can be increased)
  4. Have care with atoms, they are never garbage collected, never transform user input into atoms