[erlang-questions] Avoiding crash dump when returning {stop, Reason} from a gen_server?
Roger Lipscombe
roger@REDACTED
Tue Sep 16 12:56:15 CEST 2014
The documentation for gen_server states that handle_call etc. can
return {stop, Reason, NewState}, upon which terminate(Reason,
NewState) is called, and the gen_server stops.
The problem that I have is that it appears that Reason can only be one
of 'normal' or 'shutdown', otherwise a crash dump is generated.
Can I define other Reason values for which a crash dump is _not_ generated?
Some background:
I have a simple_one_for_one supervisor, with a set of transient
workers. If these workers crash, I want a crash dump, and I want the
worker restarted. The worker is restarted with the same arguments as
originally provided. So far so good.
I want the worker to have the ability to stop itself. This appears to
be achievable by returning {stop, normal} from handle_call,
handle_cast or handle_info. Again, this is good.
However, the original arguments to supervisor:start_child/2 come from
a data store. I also want a way for the worker to be able to request a
full restart, where the data store is re-queried.
So, I'd like to be able to return {stop, reload} from handle_call,
etc.. Another process would be monitoring the workers, and would
handle this by querying the DB and calling supervisor:start_child with
the new values.
But: anything other than 'normal' and 'shutdown' appear to cause an
error to be reported, and a crash dump to be written.
How could I implement this instead?
More information about the erlang-questions
mailing list