[Catalyst-commits] r9178 - Catalyst-Runtime/5.80/trunk/lib/Catalyst/Engine

rafl at dev.catalyst.perl.org rafl at dev.catalyst.perl.org
Tue Feb 3 10:32:45 GMT 2009


Author: rafl
Date: 2009-02-03 10:32:45 +0000 (Tue, 03 Feb 2009)
New Revision: 9178

Modified:
   Catalyst-Runtime/5.80/trunk/lib/Catalyst/Engine/FastCGI.pm
Log:
Seed the RNG in each FastCGI child process.

From: Andrew Rodland <arodland at comcast.net>
Message-Id: <200902021709.21737.arodland at comcast.net>

Due to the way FastCGI does its business, when running as an "external"
FastCGI, the perl interpreter and the Catalyst app are initialized before the
FCGI process manager does its forking. Since modern versions of Perl seed
rand() "eagerly" on startup, this leads to all of the FastCGI children
inheriting the same RNG state, and very nonrandom behavior (such as CAPTCHAs
that appear to get "stuck").

Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Engine/FastCGI.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Engine/FastCGI.pm	2009-02-03 09:44:58 UTC (rev 9177)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Engine/FastCGI.pm	2009-02-03 10:32:45 UTC (rev 9178)
@@ -102,7 +102,7 @@
     my $error = \*STDERR; # send STDERR to the web server
        $error = \*STDOUT  # send STDERR to stdout (a logfile)
          if $options->{keep_stderr}; # (if asked to)
-    
+
     my $request =
       FCGI::Request( \*STDIN, \*STDOUT, $error, \%env, $sock,
         ( $options->{nointr} ? 0 : &FCGI::FAIL_ACCEPT_ON_INTR ),
@@ -130,6 +130,9 @@
             $self->daemon_detach() if $options->{detach};
 
             $proc_manager->pm_manage();
+
+            # Give each child its own RNG state.
+            srand;
         }
         elsif ( $options->{detach} ) {
             $self->daemon_detach();
@@ -138,11 +141,11 @@
 
     while ( $request->Accept >= 0 ) {
         $proc_manager && $proc_manager->pm_pre_dispatch();
-        
+
         $self->_fix_env( \%env );
-        
+
         $class->handle_request( env => \%env );
-        
+
         $proc_manager && $proc_manager->pm_post_dispatch();
     }
 }




More information about the Catalyst-commits mailing list