Skip to content

The only tool you need to know what is happening and how to fix it.

2.8 KB
Raw Blame
// Recovery boundaries from narrow to broad, and where a panic goes when the
// boundary it reached cannot own every side effect. Render:
//   dot -Tsvg boundary-ladder.dot -o boundary-ladder.svg
// Output belongs in website/public/blog/reliable-apps-crash-so-why-does-go-recover-panics/.
// Palette matches the Traceway dark theme (app/globals.css).
digraph boundary_ladder {
  bgcolor="transparent";
  rankdir=TB;
  nodesep=0.34;
  ranksep=0.44;
  pad=0.2;
  fontname="Helvetica";

  node [shape=box, style="rounded,filled", fontname="Helvetica", fontsize=14,
        penwidth=1.3, margin="0.30,0.18",
        color="#283041", fillcolor="#151a24", fontcolor="#f4f6fb"];
  edge [color="#5a6374", penwidth=1.4, arrowsize=0.85,
        fontname="Helvetica", fontsize=11, fontcolor="#8a93a6"];

  panic  [label=<<b>a panic starts</b><br/><font color="#ff9a9d" point-size="12">nil pointer &#183; failed type assertion &#183; library bug</font>>,
          color="#ff5a5f", fillcolor="#1b1115"];
  op     [label=<<b>operation</b><br/><font color="#8a93a6" point-size="12">roll back the partial mutation before the lock is released</font>>];
  req    [label=<<b>request</b><br/><font color="#8a93a6" point-size="12">discard everything the request touched (the net/http default)</font>>];
  job    [label=<<b>durable job attempt</b><br/><font color="#8a93a6" point-size="12">fail the attempt, the queue retries from the last committed step</font>>];
  worker [label=<<b>worker</b><br/><font color="#8a93a6" point-size="12">the goroutine catches its own panic, a supervisor goroutine starts a new one</font>>];
  proc   [label=<<b>process</b><br/><font color="#ff9a9d" point-size="12">exit with a nonzero status, nothing smaller could be proven safe</font>>,
          color="#ff5a5f", fillcolor="#1b1115"];
  sup    [label=<<b>supervisor</b><br/><font color="#7ff0c8" point-size="12">systemd &#183; Docker &#183; kubelet start a clean process, with backoff</font>>,
          color="#22e0a8", fillcolor="#0c1714"];
  ok     [label=<<b>recovered</b><br/><font color="#7ff0c8" point-size="12">invariants hold again,<br/>keep serving</font>>,
          color="#22e0a8", fillcolor="#0c1714"];

  panic -> op;
  op -> req      [label="  side effects survive it: widen"];
  req -> job     [label="  side effects survive it"];
  job -> worker  [label="  side effects survive it"];
  worker -> proc [label="  side effects survive it"];
  proc -> sup    [label="  exit(1)", color="#ff5a5f", fontcolor="#ff8a8d"];

  { rank=same; job; ok; }
  op     -> ok [constraint=false, tailport=e, headport=w, color="#22e0a8", fontcolor="#7ff0c8",
                label="owns every side effect:\lrecover here\l"];
  req    -> ok [constraint=false, tailport=e, headport=w, color="#22e0a8"];
  job    -> ok [constraint=false, tailport=e, headport=w, color="#22e0a8"];
  worker -> ok [constraint=false, tailport=e, headport=w, color="#22e0a8"];
}