Hacker News new | ask | show | jobs
by edisonywh 1883 days ago
The article touched on it briefly, but perhaps it wasn't clear.

If the process dies, the Supervisor invokes the `terminate/2` callback so you're still able to process events.

Here are the relevant lines: https://github.com/plausible/analytics/blob/b724def948d51a0f...

Keep in mind you need to trap exit signal to tell the supervisor to invoke the callback, as done so here: https://github.com/plausible/analytics/blob/b724def948d51a0f...

The erlang docs also mentions this: https://erlang.org/doc/design_principles/gen_server_concepts...

2 comments

I use this callback to capture the 'data' that caused the crash, so that it can be used to recover later or better understand why the crash happened.

If I have as significantly long transaction, I can restart the transaction from transaction_id + 1 forward and then handle the actual transaction out of band by hand if its something very odd.

I usually insert a logger in these code paths too, but the crash handler is usually after the logger, which makes it easier to reason what has happened if you are dealing with mutable state.

I usually utilize this with an ETS cache to save and recover GenServer state in the event of a crash.