New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SelfLoader/fork() gotcha #8101
Comments
From @nwc10Created by @nwc10This is definitely platform dependent - I can reproduce this on x86 Linux, fork and __DATA__ don't mix. I don't think that we document this anywhere. The basic problem is with modules that lazily read from the DATA file SelfLoader breaks. $ cat Demo.pm package Demo; 1; $ cat demo.pl use Demo; my $pid = fork(); $ perl demo.pl I'm not sure if/how we can fix SelfLoader. I'm not sure where we should Nicholas Clark Perl Info
|
From nospam-abuse@ilyaz.orgI do not think this effect is documented anywhere: perl -wle 'open F, q(<), shift or die; defined fork or die; Two files x$$ are created (one per process). One of the them is Obviously, forked process share the same position in file. One of the [Sounds familiar; see It should be considered a bug in implementation of <DATA> handle. It Yours, P.S. How to reproduce: e.g., start perl -dwe0 in an XTerm (with ReadLine::Perl), then type fork Now type something to the command line in one terminal and press |
The RT System itself - Status changed from 'new' to 'open' |
From nospam-abuse@ilyaz.orgOn Sat, Oct 01, 2005 at 02:33:19PM -0700, Ilya Zakharevich wrote:
Below I made a sample implementation of protection against this (The particular case of SelfLoader is simpler since data is read in Thanks, Inline Patch--- ./lib/SelfLoader.pm-pre Wed Aug 13 23:37:40 2003
+++ ./lib/SelfLoader.pm Sat Oct 1 15:45:44 2005
@@ -51,13 +51,15 @@ sub load_stubs { shift->_load_stubs((cal
sub _load_stubs {
# $endlines is used by Devel::SelfStubber to capture lines after __END__
my($self, $callpack, $endlines) = @_;
- my $fh = \*{"${callpack}::DATA"};
+ my $ofh = \*{"${callpack}::DATA"};
my $currpack = $callpack;
my($line,$name,@lines, @stubs, $protoype);
print STDERR "SelfLoader::load_stubs($callpack)\n" if $DEBUG;
croak("$callpack doesn't contain an __DATA__ token")
- unless fileno($fh);
+ unless fileno($ofh);
+ open my $fh, '<&', $ofh or croak "reopen: $!";
+ close $ofh; # Protect: fork() shares the pointer
$Cache{"${currpack}::<DATA"} = 1; # indicate package is cached
local($/) = "\n"; |
From @rgsIlya Zakharevich wrote:
The problem with your patch is that the DATA filehandle can't be used But, IMHO fixing the fork() bug is more important than being able to
|
From nospam-abuse@ilyaz.orgOn Tue, Oct 04, 2005 at 04:28:55PM +0200, Rafael Garcia-Suarez wrote:
Make a special input layer :forkable (useful not only for DATA, but in Can somebody see problems with this? Thanks, |
From user42@zip.com.auCreated by foo@bar.comNosing around SelfLoader I wondered whether it was safe on a fork() I suspect the answer is something like not safe in general, or not until (I saw the DATA handle dup()-ing code, but I think it doesn't help, Perl Info
|
Migrated from rt.perl.org#37119 (status was 'open')
Searchable as RT37119$
The text was updated successfully, but these errors were encountered: