You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Justin Luster <ju...@sawtoothsoftware.com> on 2007/05/18 20:47:04 UTC

File Handle Issues in Mod_Perl 2.0

Hi,
 
A while back I posted an issue that I was having with mod_perl 2.0
regarding file handles.  Today I found an interesting clue to the
problem.
 
In my test script below I'm opening the same file twice in a row on
purpose without closing it.  I'm trying to replicate a possible error
condition where the file might not be closed properly.  When I run this
script on Apache 1.3 outside of Mod_Perl it works fine.  When I run this
script on Apache 1.3 with Mod_Perl 1.0 it works fine.  When I run this
script under Apache 2.0 Mod_Perl 2.0 it breaks (I'm on Red Hat Linux).
Basically on the 2nd open the file offset does not start at the
beginning of the file as it does in my other tests.  Further more it is
not consistent but starts doing the Mod_Perl weirdness of sometimes
working and sometimes not.
 
The code that is breaking has been working for years but has started to
show errors when run under Mod_Perl 2.0 Apache 2.0.
Does anyone know what might have changed in Mod_Perl 2.0 to have caused
this problem?
 
Thanks for your help,  
 
Justin
 
Here is my test script:
 
            my $strCGIPath = "";
 
            if ((exists($ENV{'SCRIPT_FILENAME'}) || (defined
($ENV{'SCRIPT_FILENAME'}))))
            {
                        #Get absolute path to cgi-bin
                        $strCGIPath = $ENV{'SCRIPT_FILENAME'};
            }
 
            $strCGIPath =~ s/\/test.pl//;
 
            my $strFileName = $strCGIPath . "/" . "test.txt";
 
            open (QUESTIONFILE,'<' . $strFileName) or print "Cant find
file";
            binmode QUESTIONFILE;
 
            #Get first line
            $_ = <QUESTIONFILE>;
 
            open (QUESTIONFILE,'<' . $strFileName) or print "Cant find
file";
            binmode QUESTIONFILE;
            seek QUESTIONFILE, 0, 0;
 
            #Get first line
            $_ = <QUESTIONFILE>;
 
            print $_;

Re: File Handle Issues in Mod_Perl 2.0

Posted by Perrin Harkins <pe...@elem.com>.
Justin,

> My main question is why would it work differently from
> mod_perl 1.0 to 2.0?

This doesn't sound like something that mod_perl would affect.  Do you
have different versions of perl, or different OSes, for these two
mod_perl servers?

- Perrin

RE: File Handle Issues in Mod_Perl 2.0

Posted by Justin Luster <ju...@sawtoothsoftware.com>.
As I said in my original email

>> script on Apache 1.3 outside of Mod_Perl it works fine. When I run
>> this script on Apache 1.3 with Mod_Perl 1.0 it works fine. When I run

>> this script under Apache 2.0 Mod_Perl 2.0 it breaks (I'm on Red Hat 
>> Linux). Basically on the 2^nd open the file offset does not start at 
>> the beginning of the file as it does in my other tests. Further more 
>> it is not consistent but starts doing the Mod_Perl weirdness of 
>> sometimes working and sometimes not.

So after I open a file I would expect the first line to be read would be
the first line of the file.  In Mod_Perl 1 if I open the file twice in a
row (I would not normally do this but I'm trying to simulate an error
condition of when a file might accidentally not be closed before opening
again) everything works as expected, the 2nd time it is opened it still
reads the first line.  When I move into Mod_Perl two this test case
fails.  The 2nd time the file is opened it does not start reading at the
top of the file but starts reading the 2nd line etc.

Thanks,

Justin

-----Original Message-----
From: Foo JH [mailto:jhfoo-ml@extracktor.com] 
Sent: Monday, May 21, 2007 9:56 PM
To: Justin Luster
Cc: modperl@perl.apache.org
Subject: Re: File Handle Issues in Mod_Perl 2.0

What kind of errors specifically are you getting?

Justin Luster wrote:
> I'm not closing the file on purpose to try and simulate an error
> condition.  My main question is why would it work differently from
> mod_perl 1.0 to 2.0?
>
> Thanks,
>
> Justin
>
> -----Original Message-----
> From: Foo JH [mailto:jhfoo-ml@extracktor.com] 
> Sent: Sunday, May 20, 2007 7:15 PM
> To: Justin Luster
> Cc: modperl@perl.apache.org
> Subject: Re: File Handle Issues in Mod_Perl 2.0
>
> Could be some internal optimsation issue.
>
> But I'd say that your best bet is to really close the file after
you're 
> done with it, and not let it hang around. This so especially when you 
> are expecting multiple threads/ processes accessing the same file.
>
> Justin Luster wrote:
>   
>> Hi,
>>
>> A while back I posted an issue that I was having with mod_perl 2.0 
>> regarding file handles. Today I found an interesting clue to the
>>     
> problem.
>   
>> In my test script below I'm opening the same file twice in a row on 
>> purpose without closing it. I'm trying to replicate a possible error 
>> condition where the file might not be closed properly. When I run
this
>>     
>
>   
>> script on Apache 1.3 outside of Mod_Perl it works fine. When I run 
>> this script on Apache 1.3 with Mod_Perl 1.0 it works fine. When I run

>> this script under Apache 2.0 Mod_Perl 2.0 it breaks (I'm on Red Hat 
>> Linux). Basically on the 2^nd open the file offset does not start at 
>> the beginning of the file as it does in my other tests. Further more 
>> it is not consistent but starts doing the Mod_Perl weirdness of 
>> sometimes working and sometimes not.
>>
>> The code that is breaking has been working for years but has started 
>> to show errors when run under Mod_Perl 2.0 Apache 2.0.
>>
>> Does anyone know what might have changed in Mod_Perl 2.0 to have 
>> caused this problem?
>>
>> Thanks for your help,
>>
>> Justin
>>
>> Here is my test script:
>>
>> my $strCGIPath = "";
>>
>> if ((exists($ENV{'SCRIPT_FILENAME'}) || (defined 
>> ($ENV{'SCRIPT_FILENAME'}))))
>>
>> {
>>
>> #Get absolute path to cgi-bin
>>
>> $strCGIPath = $ENV{'SCRIPT_FILENAME'};
>>
>> }
>>
>> $strCGIPath =~ s/\/test.pl//;
>>
>> my $strFileName = $strCGIPath . "/" . "test.txt";
>>
>> open (QUESTIONFILE,'<' . $strFileName) or print "Cant find file";
>>
>> binmode QUESTIONFILE;
>>
>> #Get first line
>>
>> $_ = <QUESTIONFILE>;
>>
>> open (QUESTIONFILE,'<' . $strFileName) or print "Cant find file";
>>
>> binmode QUESTIONFILE;
>>
>> seek QUESTIONFILE, 0, 0;
>>
>> #Get first line
>>
>> $_ = <QUESTIONFILE>;
>>
>> print $_;
>>
>>     
>
>
>   




Re: File Handle Issues in Mod_Perl 2.0

Posted by Foo JH <jh...@extracktor.com>.
What kind of errors specifically are you getting?

Justin Luster wrote:
> I'm not closing the file on purpose to try and simulate an error
> condition.  My main question is why would it work differently from
> mod_perl 1.0 to 2.0?
>
> Thanks,
>
> Justin
>
> -----Original Message-----
> From: Foo JH [mailto:jhfoo-ml@extracktor.com] 
> Sent: Sunday, May 20, 2007 7:15 PM
> To: Justin Luster
> Cc: modperl@perl.apache.org
> Subject: Re: File Handle Issues in Mod_Perl 2.0
>
> Could be some internal optimsation issue.
>
> But I'd say that your best bet is to really close the file after you're 
> done with it, and not let it hang around. This so especially when you 
> are expecting multiple threads/ processes accessing the same file.
>
> Justin Luster wrote:
>   
>> Hi,
>>
>> A while back I posted an issue that I was having with mod_perl 2.0 
>> regarding file handles. Today I found an interesting clue to the
>>     
> problem.
>   
>> In my test script below I'm opening the same file twice in a row on 
>> purpose without closing it. I'm trying to replicate a possible error 
>> condition where the file might not be closed properly. When I run this
>>     
>
>   
>> script on Apache 1.3 outside of Mod_Perl it works fine. When I run 
>> this script on Apache 1.3 with Mod_Perl 1.0 it works fine. When I run 
>> this script under Apache 2.0 Mod_Perl 2.0 it breaks (I'm on Red Hat 
>> Linux). Basically on the 2^nd open the file offset does not start at 
>> the beginning of the file as it does in my other tests. Further more 
>> it is not consistent but starts doing the Mod_Perl weirdness of 
>> sometimes working and sometimes not.
>>
>> The code that is breaking has been working for years but has started 
>> to show errors when run under Mod_Perl 2.0 Apache 2.0.
>>
>> Does anyone know what might have changed in Mod_Perl 2.0 to have 
>> caused this problem?
>>
>> Thanks for your help,
>>
>> Justin
>>
>> Here is my test script:
>>
>> my $strCGIPath = "";
>>
>> if ((exists($ENV{'SCRIPT_FILENAME'}) || (defined 
>> ($ENV{'SCRIPT_FILENAME'}))))
>>
>> {
>>
>> #Get absolute path to cgi-bin
>>
>> $strCGIPath = $ENV{'SCRIPT_FILENAME'};
>>
>> }
>>
>> $strCGIPath =~ s/\/test.pl//;
>>
>> my $strFileName = $strCGIPath . "/" . "test.txt";
>>
>> open (QUESTIONFILE,'<' . $strFileName) or print "Cant find file";
>>
>> binmode QUESTIONFILE;
>>
>> #Get first line
>>
>> $_ = <QUESTIONFILE>;
>>
>> open (QUESTIONFILE,'<' . $strFileName) or print "Cant find file";
>>
>> binmode QUESTIONFILE;
>>
>> seek QUESTIONFILE, 0, 0;
>>
>> #Get first line
>>
>> $_ = <QUESTIONFILE>;
>>
>> print $_;
>>
>>     
>
>
>   


RE: File Handle Issues in Mod_Perl 2.0

Posted by Justin Luster <ju...@sawtoothsoftware.com>.
I'm not closing the file on purpose to try and simulate an error
condition.  My main question is why would it work differently from
mod_perl 1.0 to 2.0?

Thanks,

Justin

-----Original Message-----
From: Foo JH [mailto:jhfoo-ml@extracktor.com] 
Sent: Sunday, May 20, 2007 7:15 PM
To: Justin Luster
Cc: modperl@perl.apache.org
Subject: Re: File Handle Issues in Mod_Perl 2.0

Could be some internal optimsation issue.

But I'd say that your best bet is to really close the file after you're 
done with it, and not let it hang around. This so especially when you 
are expecting multiple threads/ processes accessing the same file.

Justin Luster wrote:
>
> Hi,
>
> A while back I posted an issue that I was having with mod_perl 2.0 
> regarding file handles. Today I found an interesting clue to the
problem.
>
> In my test script below I'm opening the same file twice in a row on 
> purpose without closing it. I'm trying to replicate a possible error 
> condition where the file might not be closed properly. When I run this

> script on Apache 1.3 outside of Mod_Perl it works fine. When I run 
> this script on Apache 1.3 with Mod_Perl 1.0 it works fine. When I run 
> this script under Apache 2.0 Mod_Perl 2.0 it breaks (I'm on Red Hat 
> Linux). Basically on the 2^nd open the file offset does not start at 
> the beginning of the file as it does in my other tests. Further more 
> it is not consistent but starts doing the Mod_Perl weirdness of 
> sometimes working and sometimes not.
>
> The code that is breaking has been working for years but has started 
> to show errors when run under Mod_Perl 2.0 Apache 2.0.
>
> Does anyone know what might have changed in Mod_Perl 2.0 to have 
> caused this problem?
>
> Thanks for your help,
>
> Justin
>
> Here is my test script:
>
> my $strCGIPath = "";
>
> if ((exists($ENV{'SCRIPT_FILENAME'}) || (defined 
> ($ENV{'SCRIPT_FILENAME'}))))
>
> {
>
> #Get absolute path to cgi-bin
>
> $strCGIPath = $ENV{'SCRIPT_FILENAME'};
>
> }
>
> $strCGIPath =~ s/\/test.pl//;
>
> my $strFileName = $strCGIPath . "/" . "test.txt";
>
> open (QUESTIONFILE,'<' . $strFileName) or print "Cant find file";
>
> binmode QUESTIONFILE;
>
> #Get first line
>
> $_ = <QUESTIONFILE>;
>
> open (QUESTIONFILE,'<' . $strFileName) or print "Cant find file";
>
> binmode QUESTIONFILE;
>
> seek QUESTIONFILE, 0, 0;
>
> #Get first line
>
> $_ = <QUESTIONFILE>;
>
> print $_;
>



Re: File Handle Issues in Mod_Perl 2.0

Posted by Foo JH <jh...@extracktor.com>.
Could be some internal optimsation issue.

But I'd say that your best bet is to really close the file after you're 
done with it, and not let it hang around. This so especially when you 
are expecting multiple threads/ processes accessing the same file.

Justin Luster wrote:
>
> Hi,
>
> A while back I posted an issue that I was having with mod_perl 2.0 
> regarding file handles. Today I found an interesting clue to the problem.
>
> In my test script below I’m opening the same file twice in a row on 
> purpose without closing it. I’m trying to replicate a possible error 
> condition where the file might not be closed properly. When I run this 
> script on Apache 1.3 outside of Mod_Perl it works fine. When I run 
> this script on Apache 1.3 with Mod_Perl 1.0 it works fine. When I run 
> this script under Apache 2.0 Mod_Perl 2.0 it breaks (I’m on Red Hat 
> Linux). Basically on the 2^nd open the file offset does not start at 
> the beginning of the file as it does in my other tests. Further more 
> it is not consistent but starts doing the Mod_Perl weirdness of 
> sometimes working and sometimes not.
>
> The code that is breaking has been working for years but has started 
> to show errors when run under Mod_Perl 2.0 Apache 2.0.
>
> Does anyone know what might have changed in Mod_Perl 2.0 to have 
> caused this problem?
>
> Thanks for your help,
>
> Justin
>
> Here is my test script:
>
> my $strCGIPath = "";
>
> if ((exists($ENV{'SCRIPT_FILENAME'}) || (defined 
> ($ENV{'SCRIPT_FILENAME'}))))
>
> {
>
> #Get absolute path to cgi-bin
>
> $strCGIPath = $ENV{'SCRIPT_FILENAME'};
>
> }
>
> $strCGIPath =~ s/\/test.pl//;
>
> my $strFileName = $strCGIPath . "/" . "test.txt";
>
> open (QUESTIONFILE,'<' . $strFileName) or print "Cant find file";
>
> binmode QUESTIONFILE;
>
> #Get first line
>
> $_ = <QUESTIONFILE>;
>
> open (QUESTIONFILE,'<' . $strFileName) or print "Cant find file";
>
> binmode QUESTIONFILE;
>
> seek QUESTIONFILE, 0, 0;
>
> #Get first line
>
> $_ = <QUESTIONFILE>;
>
> print $_;
>