Subject: | No way to get at fatal exceptions from children when using setsid |
Hi,
We're finishing up a project using Net::Server and during final
debugging the issue came up that when children throw unhandled
exceptions, there is no way to know about them.
Currently the exceptions in children thrown from process_request
are handled like this:
my $ok = eval { $self->run_client_connection; 1 };
if (! $ok) {
print $write "$$ exiting\n";
die $@;
}
This means the exception only ever appears in STDERR, which is
for all purposes and intents invisible when using setsid (as we
do by default). I've tried writing a custom __DIE__ handler but
that is rarely a perfect solution... (at least it gets the
exception into the logs)
I think ideally the die $@ should be replaced by a customizable
hook such as (simplified, probably)
sub child_exception_hook {
die $_[0];
}
which would leave the option for users to do e.g. (also
simplified)
package MyDaemon;
sub child_exception_hook {
my $exception = shift;
if ($exception =~ m/expected/) {
Log::Log4perl->get_logger->warning('known exception: foobar');
} else {
Log::Log4perl->get_logger->fatal("unhandled exception! message: $exception");
# rethrow and really die
die $exception;
# or maybe even notify the parent that this is really a
# terminal condition and we should abort everything
}
}
What do you think?
I'm willing to write the patch if necessary.