[erlang-questions] terminating a gen_server
Tue Sep 11 01:32:47 CEST 2007
On 10/09/2007, Anthony Shipman <als@REDACTED> wrote:
> I've found that I can do exit(Pid, shutdown) where Pid is a gen_server and it
> will nicely shut down, calling Mod:terminate.
> I can't see how this works. The server is not trapping exit signals so I would
> expect it to just exit without calling Mod:terminate.
> The code in gen_server:loop seems to be deliberately written to support this
> behaviour. Can we rely on it?
This should not be possible. Can you post your code? If not, what
version of erlang are you using? The Mod:terminate function should
only be called if the gen_server is trapping exits. According to the
Note that a gen_server does not trap exit signals automatically, this
must be explicitly initiated in the callback module.
If the gen_server is part of a supervision tree and is ordered by its
supervisor to terminate, this function will be called with
Reason=shutdown if the following conditions apply:
* the gen_server has been set to trap exit signals, and
* the shutdown strategy as defined in the supervisor's child
specification is an integer timeout value, not brutal_kill.
I've tested this with R11B-1 and it does what it says on the tin.
More information about the erlang-questions