↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

Building Distributed Systems in Elixir: Part 4 — Process Linking

The article shows that process links create a bidirectional failure relationship between BEAM processes. Unlike monitors, links are not just observation; an abnormal exit in a linked process can terminate the other process unless exits are trapped.

It also shows how Process.flag(:trap_exit, true) converts the exit signal into a regular {:EXIT, from_pid, reason} mailbox message. That lets the parent process receive and inspect the worker’s failure, while still leaving restart decisions for later supervisor logic.

Reading notes
#

  • spawn_link/1 starts and links a process atomically, avoiding a gap where the child could crash before the link exists.
  • A linked crash propagates as an exit signal, so an abnormal worker exit can terminate the parent.
  • Normal exits do not ordinarily take down linked processes that are not trapping exits.
  • Process.flag(:trap_exit, true) changes the incoming exit signal into a mailbox message.
  • The trapped message has the shape {:EXIT, from_pid, reason}.
  • ^worker pins the receive pattern to the specific linked worker PID.
  • Trapping exits lets the parent observe the failure and stay alive.
  • Links and monitors are different: monitors are one-way and produce {:DOWN, ...}, while links are bidirectional and affect process lifecycles.
  • The article treats links as a step before supervision, since restart policy still has to be decided separately.
  • The next part will build a supervisor from scratch and use the trapped exit to start a replacement worker.

Series
#

Building Distributed Systems in Elixir, by krishnadaspc. Research: Distributed Systems Patterns.