[erlang-questions] [Q]: Terminating supervisor and its workers

Ladislav Lenart lenartlad@REDACTED
Thu Jul 26 10:56:44 CEST 2007


Samuel Rivas wrote:
> Ladislav Lenart wrote:
>> Lennart Öhman wrote:
>>> have you turned trap_exit to true in your worker?
>> No, I haven't. And frankly I don't want to. I am using
>> a standard piece of library functionality so why I have
>> to tweak my callback module to make it work? (I was
>> hoping that gen_server:start and gen_server:start_link
>> will make the difference.)
>>
>> But if this is the Erlang way, I will do it.
> 
>   If you do not trap exits, the process will die at the moment it receives the
> 'EXIT' signal. The OTP-way is putting a process_flag(trap_exit, true) in the
> gen_server's init function and write your cleanup code in the gen_server's
> terminate/2 function.

I browsed gen_server sources and found that it explicitly
catches any exit signal from its parent (not only shutdown)
and terminates itself with same reason (just like OTP doc
says). So the only thing missing is the trap_exit flag as
you all pointed me out.

But what I dislike (a little) about trapping exits in general
is that it can easily "hide errors". For example, if my process
is linked with something else and that something crashes, my
process would normally crash but because it is trapping exits
now, I must explicitly handle the exit signal (either to crash
as before or to restart that buggy thingy).

Thank you all once again for your replies.

Ladislav Lenart




More information about the erlang-questions mailing list