Fixed issue where development server running in fork mode did not properly exit after...
Andy Grundman [Wed, 16 May 2007 03:00:39 +0000 (03:00 +0000)]
Changes
lib/Catalyst/Engine/HTTP.pm

diff --git a/Changes b/Changes
index 081b1a4..f106eec 100644 (file)
--- a/Changes
+++ b/Changes
@@ -3,6 +3,9 @@ This file documents the revision history for Perl extension Catalyst.
 5.7008
         - Fixed a bug where Content-Length could be set to 0 if a filehandle
           object in $c->response->body did not report a size.
+        - Fixed issue where development server running in fork mode did not
+          properly exit after a write error.
+          (http://rt.cpan.org/Ticket/Display.html?id=27135)
 
 5.7007  2007-03-13 14:18:00
         - Many performance improvements by not using URI.pm:
index 20da4d5..f4fef51 100644 (file)
@@ -276,17 +276,30 @@ sub run {
             unless ( uc($method) eq 'RESTART' ) {
 
                 # Fork
-                if ( $options->{fork} ) { next if $pid = fork }
+                if ( $options->{fork} ) { 
+                    if ( $pid = fork ) {
+                        DEBUG && warn "Forked child $pid\n";
+                        next;
+                    }
+                }
 
                 $self->_handler( $class, $port, $method, $uri, $protocol );
             
                 if ( my $error = delete $self->{_write_error} ) {
                     DEBUG && warn "Write error: $error\n";
                     close Remote;
-                    next LISTEN;
+                    
+                    if ( !defined $pid ) {
+                        next LISTEN;
+                    }
                 }
 
-                $daemon->close if defined $pid;
+                if ( defined $pid ) {
+                    # Child process, close connection and exit
+                    DEBUG && warn "Child process exiting\n";
+                    $daemon->close;
+                    exit;
+                }
             }
             else {
                 my $sockdata = $self->_socket_data( \*Remote );
@@ -302,8 +315,6 @@ sub run {
                     last;
                 }
             }
-
-            exit if defined $pid;
         }
         continue {
             close Remote;