[erlang-questions] Avoiding crash dump when returning {stop, Reason} from a gen_server?

Roger Lipscombe roger@REDACTED
Tue Sep 16 13:45:19 CEST 2014

On 16 September 2014 12:20, Roger Lipscombe <roger@REDACTED> wrote:
> On 16 September 2014 12:14, Viacheslav V. Kovalev <kovyl2404@REDACTED> wrote:
>> It looks like that you getting crash dumps because supervisor exhausts
>> max restarts count when trying infinitely restart children, that
>> stopping abnormally (from supervisor's point of view).
> No. I get crash dumps for the *worker* whenever it stops with anything
> other than 'normal' or 'shutdown'. I've not tried {shutdown, Term}
> yet, though. If the restart frequency is exceeded, *then* I get a
> crash dump for the supervisor.

My apologies. I was getting confused. I'm using lager, and what I'm
seeing is "CRASH REPORT" errors in the log file. I mistakenly thought
that these equated to erl_crash.dump being written. They don't.

These are scary enough by themselves, but by talking about "crash
dumps", I was being confusing.

I dug into the source code to attempt to answer some of the rest of my
question: see https://github.com/erlang/otp/blob/maint/lib/stdlib/src/gen_server.erl#L636
and https://github.com/erlang/otp/blob/maint/lib/stdlib/src/gen_server.erl#L734.

If handle_call, etc., return {stop, Reason}, terminate(Reason), and
then there's a "case Reason of..." expression, where normal, shutdown
and {shutdown, _} are translated to exit(Reason), but *anything* else
results in a call to error_info, which calls error_logger:format, and
then exit(Reason).

The call to error_logger hits lager, which outputs the scary-looking
message to the log, and then writes to its "crash.log" file.

So, basically, it appears that -- assuming that the rest of my plan is
sound -- I should return {stop, {shutdown, Term}, NewState}, and
handle the {shutdown, Term} differently in my monitoring process.

More information about the erlang-questions mailing list