[erlang-questions] gen_event event handlers and supervisors

Garrett Smith g@REDACTED
Sat Jan 16 20:55:38 CET 2010


Heh, I also missed the fact that event handlers /are not processes/ :)

The look an awful lot like OTP process behaviors from the callback
API, which threw me.

So, nevermind ;)

On Fri, Jan 15, 2010 at 7:17 PM, Jayson Vantuyl <kagato@REDACTED> wrote:
> I think part of the disconnect here is that gen_event is usually used across subsystems.  For example, take the log handlers.  The logging system doesn't know what the failure conditions are for any log handler that is plugged into it.  In terms of maintaining system integrity, it's rarely a good idea to let another buggy module kill a central subsystem.  Instead, you have the mechanism to notify the other subsystem and let it handle it.  You'll rarely see the gen_event itself running under the same supervisor as one of these coordinating gen_server you describe.
>
> More concretely, take a look at LIBDIR/kernel-*/src/error_logger.erl and LIBDIR/sasl-*/src/sasl.erl.  They don't use supervised handlers, but it illustrates how the gen_event (in this case registered as error_logger) is the nexus of a number of other systems (sasl, the default console handler, any logfiles you install).  A logfile is a good example of why silently removing the logger makes sense.  If the disk is full or becomes unavailable, that handler crashes, and removal is the only option that makes sense.  I think that this use-case makes it pretty clear why there's that behavior.  Interestingly, I don't see any supervised handlers (registered with add_sup_handler) in OTP itself, so I can't really refer you to any other cases where it's used.
>
> On Jan 15, 2010, at 4:21 PM, Garrett Smith wrote:
>
>> It seems that in order to hook gen_event event handlers into an OTP
>> supervisory tree, one must "wrap" them in a gen_server, adding them
>> using the add_sup_handler and then handling the EXIT message by
>> crashing, letting the supervisor handle the crash.
>>
>> Is the recommended approach for building fault tolerance into
>> gen_event event handlers?
>>
>> If this is the case, it strikes me as something one would do 100% of
>> the time in production settings -- i.e. who would ever tolerate the
>> silent failure and unregistration of an event handler??
>>
>> I'm curious how others handle this problem. Do you routinely create a
>> gen_server to effectively plug the event handler into a supervisory
>> tree? Or is there another predominating pattern that bypasses
>> gen_event and accomplishes something similar (i.e. broadcast style
>> event handling)?
>>
>> Garrett
>>
>> ________________________________________________________________
>> erlang-questions mailing list. See http://www.erlang.org/faq.html
>> erlang-questions (at) erlang.org
>>
>
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>


More information about the erlang-questions mailing list