Hacker News new | ask | show | jobs
by chantepierre 483 days ago
I love to see "well-known" people in the Elixir community endorsing and actively developing that kind of approach. Our VM and runtime does so much and is so well suited to orchestrating other languages and tech that it sometimes feels there's a standard track and an off-road track.

The difference between an off-road "sounds dangerous" idea and its safe execution is often only the quantity of work but our runtime encourages that. Here, it's a NIF so there's still a bit of risk, but it's always possible to spawn a separate BEAM instance and distribute yourself with it.

Toy example that illustrates it, first crashing with a NIF that is made to segfault :

  my_nif_app iex --name my_app@127.0.0.1 --cookie cookie -S mix
  iex(my_app@127.0.0.1)1> MyNifApp.crash
  [1]    97437 segmentation fault
In the second example, we have a "SafeNif" module that spawns another elixir node, connects to it, and runs the unsafe operation on it.

  my_nif_app iex --name my_app@127.0.0.1 --cookie cookie -S mix
  iex(my_app@127.0.0.1)1> MyNifApp.SafeNif.call(MyNifApp, :crash, [])
  Starting temporary node: safe_nif_4998973
  Starting node with: elixir --name safe_nif_4998973@127.0.0.1 --cookie :cookie --no-halt /tmp/safe_nif_4998973_init.exs
  Successfully connected to temporary node
  Calling MyNifApp.crash() on temporary node
  :error
  iex(my_app@127.0.0.1)2>
Thankfully Python, Zig and Rust should be good to go without that kind of dance :) .
1 comments

Its a neat way to do it - spin a temporary one, which can crash all it wants without affecting the other nodes. Fits like a glove to BEAM.