Subject: | undefs in env and clean exits |
If you want to run your catalyst app (script/myapp_server.pl) under a
profiler, say NYTProf, they don't like the program to be just killed.
It would be nice if the server would catch INT and QUIT and just exit,
allowing the app to tear itself down gracefully.
If %ENV gets undef values in it, the Catalyst::Engine::HTTP module will
spew warnings for each request. Annoying, and when I figure out which
other module is doing that, I'll complain there too.
Here's a patch against Catalyst-Runtime 5.80007 (being what I've got
access to here).
Subject: | Catalyst-Engine-HTTP.patch |
--- /ms/dist/perl5/PROJ/Catalyst-Runtime/5.80007/lib/perl5/Catalyst/Engine/HTTP.pm 2009-06-20 23:32:59.621976916 -0400
+++ lib/Catalyst/Engine/HTTP.pm 2010-07-29 10:59:39.992521652 -0400
@@ -193,7 +193,10 @@
}
my $restart = 0;
+ my $shutdown = 0;
local $SIG{CHLD} = 'IGNORE';
+ local $SIG{INT} = sub { $shutdown = 1; };
+ local $SIG{QUIT} = sub { $shutdown = 1; };
my $allowed = $options->{allowed} || { '127.0.0.1' => '255.255.255.255' };
my $addr = $host ? inet_aton($host) : INADDR_ANY;
@@ -256,7 +259,7 @@
};
LISTEN:
- while ( !$restart ) {
+ while ( !$restart and !$shutdown ) {
while ( accept( Remote, $daemon ) ) {
DEBUG && warn "New connection\n";
@@ -327,11 +330,10 @@
$daemon->close;
- DEBUG && warn "Shutting down\n";
-
if ($restart) {
$SIG{CHLD} = 'DEFAULT';
wait;
+ DEBUG && warn "Re-starting\n";
### if the standalone server was invoked with perl -I .. we will loose
### those include dirs upon re-exec. So add them to PERL5LIB, so they
@@ -342,6 +344,7 @@
exec $^X, $0, @{ $options->{argv} };
}
+ DEBUG && warn "Shutting down\n";
exit;
}
@@ -357,6 +360,15 @@
my $sockdata = $self->_socket_data( \*Remote );
my %copy_of_env = %ENV;
+ # Without this hack, it will warn of undefs every time it handles
+ # a new request and assigns %copy_of_env to th enewly build environment.
+ foreach my $key (keys %copy_of_env) {
+ if ( not defined $copy_of_env{$key} ) {
+ # warn "somehow '$key' has an undef in it\n";
+ $copy_of_env{$key} = '';
+ }
+ }
+
my $sel = IO::Select->new;
$sel->add( \*STDIN );