Skip Menu |

This queue is for tickets about the Catalyst-Runtime CPAN distribution.

Report information
The Basics
Id: 43589
Status: resolved
Priority: 0/
Queue: Catalyst-Runtime

People
Owner: Nobody in particular
Requestors: sk [...] intertivity.com
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 5.7012
Fixed in: (no value)



using restart causes perl.exe to crash on Vista.
On Tue Feb 24 18:40:47 2009, ESSKAR wrote: Show quoted text
> using restart causes perl.exe to crash on Vista. >
it seems to be unless ( my $restarter = fork() ) { since unless ( 0 and my $restarter = fork() ) { will NOT crash perl. maybe there could be a workaround using threads. i tried it both with active and strawberry perl.
On Tue Feb 24 18:55:56 2009, ESSKAR wrote: Show quoted text
> On Tue Feb 24 18:40:47 2009, ESSKAR wrote:
> > using restart causes perl.exe to crash on Vista. > >
> it seems to be > > unless ( my $restarter = fork() ) { > > since > > unless ( 0 and my $restarter = fork() ) { > > will NOT crash perl. > maybe there could be a workaround using threads. > i tried it both with active and strawberry perl. >
please find an modified version of Restarter.pm attached. uses a new option '$options->{use_threads}' to determine whether or not to use threads. forces threads under win vista
package Catalyst::Engine::HTTP::Restarter; use strict; use warnings; use base 'Catalyst::Engine::HTTP'; use Catalyst::Engine::HTTP::Restarter::Watcher; use NEXT; use Config; sub _watching { my ( $self, $class, $port, $host, $options ) = @_; my $watcher = Catalyst::Engine::HTTP::Restarter::Watcher->new( directory => ( $options->{restart_directory} || File::Spec->catdir( $FindBin::Bin, '..' ) ), follow_symlinks => $options->{follow_symlinks}, regex => $options->{restart_regex}, delay => $options->{restart_delay}, ); $host ||= '127.0.0.1'; while (1) { # poll for changed files my @changed_files = $watcher->watch(); # check if our parent process has died exit if $^O ne 'MSWin32' and getppid == 1; # Restart if any files have changed if (@changed_files) { my $files = join ', ', @changed_files; print STDERR qq/File(s) "$files" modified, restarting\n\n/; require IO::Socket::INET; require HTTP::Headers; require HTTP::Request; my $client = IO::Socket::INET->new( PeerAddr => $host, PeerPort => $port ) or die "Can't create client socket (is server running?): ", $!; # build the Kill request my $req = HTTP::Request->new( 'RESTART', '/', HTTP::Headers->new( 'Connection' => 'close' ) ); $req->protocol('HTTP/1.0'); $client->send( $req->as_string ) or die "Can't send restart instruction: ", $!; $client->close(); exit; } } } sub run { my ( $self, $class, $port, $host, $options ) = @_; $options ||= {}; $options->{use_threads} ||= ( $Config{osname} eq 'MSWin32' and $Config{osvers} >= 5 ); # force threads in M$ Vista unless( $options->{use_threads} ) { # Setup restarter unless ( my $restarter = fork() ) { # Prepare close STDIN; close STDOUT; $self->_watching( $class, $port, $host, $options ); } } else { # fork seems to break active & strawberry) perl on at least vista require threads; my $thr = threads->create( { 'stack_size' => 8*4096, 'exit' => 'thread_only' }, sub { $self->_watching( $class, $port, $host, $options ); } ); $thr->detach(); # put it in the background } return $self->NEXT::run( $class, $port, $host, $options ); } 1; __END__ =head1 NAME Catalyst::Engine::HTTP::Restarter - Catalyst Auto-Restarting HTTP Engine =head1 SYNOPSIS script/myapp_server.pl -restart =head1 DESCRIPTION The Restarter engine will monitor files in your application for changes and restart the server when any changes are detected. =head1 METHODS =head2 run =head1 SEE ALSO L<Catalyst>, L<Catalyst::Engine::HTTP>, L<Catalyst::Engine::CGI>, L<Catalyst::Engine>. =head1 AUTHORS Catalyst Contributors, see Catalyst.pm =head1 THANKS Many parts are ripped out of C<HTTP::Server::Simple> by Jesse Vincent. =head1 COPYRIGHT This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. =cut
Subject: Re: [rt.cpan.org #43589] Use threads in win32 strawberry perl
Date: Fri, 22 May 2009 01:41:58 +0200
To: bug-Catalyst-Runtime [...] rt.cpan.org
From: kmx <kmx [...] volny.cz>
Hi, I am not sure whether the changes in current Catalyst::Runtime truk (namely http://dev.catalystframework.org/svnweb/Catalyst/revision/?rev=10201) are the response to this TR but I have strong doubts if it is the right way. 1) It (current trunk) seems not to work on Win32/strawberry 5.8.9 (it crashes) - before the patch it worked fine 2) I guess that the original problem - reporter by ESSKAR - problem was due to the bug in Win32 perl 5.10 (I have tried to ask strawberry guys but without success see http://rt.cpan.org/Public/Bug/Display.html?id=45726). You can easily check this little program: --- use namespace::clean; if (fork()) { print "1\n"; } else { print "2\n"; } --- It causes a perl.exe crash on Win32/strawberry 5.10, it does not work on Win32/ActiveState 5.10. However it does work on Win32/strawberry 5.8 and all other UNIX perls I have tested. Commenting out "use namespace::clean;" "solves" the crash. So the problem is that on Win32 Perl 5.10 "namespace::clean" cannot go with "fork". But generally fork should work on Win32 - remember that in Win32 environment the perl "fork" call is implemented via threads and that might be the reason why "fork" on Win32 (in fact a pseudo fork emulated by threads) sometimes behaves slightly differently than on UNIX. In my opinion the right way is to stay with fork() with the more or less common code for Win32 and UNIX. -- kmx
I'm going to resolve this - I agree with kmx that fork() is the right solution here, and this is a bug with perl itself that it segfaults (only on some platforms).. I'd recommend pushing this bug back to strawberry, where it can go upstream to perl itself.