You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by pubert na <pu...@gmail.com> on 2007/07/03 00:47:11 UTC
header issues etc...
I was able to narrow down the problem I was having, and produce a test case
for you folks. Below are two relatively self-explanatory files. If I
navigate to test.cgi, it will appear to load the page properly, but if I hit
the reload button a bunch of times in a row, the error_log will log
segfaults. I pasted a sample at the bottom of this message. I'd appreciate
any help at all. Obviously the issue is coming from CGI.pm's header
function, which *should* be ok with mod_perl2. Thanks again. --Pubert
##>BEGIN FILE test.cgi<
#!/usr/bin/perl
use lib qw(/var/www/cgi-bin/);;
use strict;
use CGI;
use testclass;
my $cgi=new CGI;
my $tc = testclass->new({CGI=>$cgi});
$tc->doit();
1;
##>BEGIN FILE testclass.pm<
package testclass;
my $self;
#########################################################################################################
sub new {
#########################################################################################################
# This is the
constructor.
my ( $class, $args ) = @_;
return $self if defined $self;
$self = {};
bless $self, $class;
$self->{CGI}=$args->{CGI};
return $self;
}
sub doit{
print $self->{CGI}->header;
print "hello";
}
1;
>Begin error_log snipper<
[Mon Jul 02 18:45:34 2007] [notice] SIGHUP received. Attempting to restart
[Mon Jul 02 18:45:34 2007] [notice] Digest: generating secret for digest
authentication ...
[Mon Jul 02 18:45:34 2007] [notice] Digest: done
[Mon Jul 02 18:45:34 2007] [notice] Apache/2.2.4 (Unix) DAV/2
mod_apreq2-20051231/2.6.1 mod_perl/2.0.2 Perl/v5.8.8 configured -- resuming
normal operations
[Mon Jul 02 18:45:39 2007] [notice] child pid 7925 exit signal Segmentation
fault (11)
[Mon Jul 02 18:45:39 2007] [notice] child pid 7926 exit signal Segmentation
fault (11)
[Mon Jul 02 18:45:39 2007] [notice] child pid 7927 exit signal Segmentation
fault (11)
[Mon Jul 02 18:45:40 2007] [notice] child pid 7928 exit signal Segmentation
fault (11)
[Mon Jul 02 18:45:40 2007] [notice] child pid 7929 exit signal Segmentation
fault (11)
[Mon Jul 02 18:45:40 2007] [notice] child pid 7931 exit signal Segmentation
fault (11)
Re: header issues etc...
Posted by Perrin Harkins <pe...@elem.com>.
On 7/4/07, pubert na <pu...@gmail.com> wrote:
> Won't multiple simultaneous requests change the "our" variables
> unpredictably since they all have access to the symbol table?
No. Every child process is completely separate and they don't share
anything. Each process only handles one request at a time. And you
never modify this variable after the first time the code runs anyway.
- Perrin
Re: header issues etc...
Posted by pubert na <pu...@gmail.com>.
Won't multiple simultaneous requests change the "our" variables
unpredictably since they all have access to the symbol table?
On 7/3/07, Perrin Harkins <pe...@elem.com> wrote:
>
> On 7/3/07, Jonathan Vanasco <jv...@2xlp.com> wrote:
> > i prefer storing them as class variables and using a public method to
> > provide access
> >
> > ie:
> >
> > package myfactory;
> > my $object= object->new();
> > sub get_object { return $object ;}
>
> Using closures just makes it more confusing. Class variables are
> usually implemented as globals, i.e. our $object, not my $object.
>
> - Perrin
>
Re: header issues etc...
Posted by Jonathan Vanasco <jv...@2xlp.com>.
On Jul 3, 2007, at 10:37 PM, Perrin Harkins wrote:
> Using closures just makes it more confusing. Class variables are
> usually implemented as globals, i.e. our $object, not my $object.
agreed.
i just prefer using methods locked into version numbers for a
consistent api. this way the variable names can change, and the only
way to get/modify vars is through the api methods.
// Jonathan Vanasco
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
| CEO/Founder SyndiClick Networks
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
| Founder/CTO/CVO
| FindMeOn.com - The cure for Multiple Web Personality Disorder
| Web Identity Management and 3D Social Networking
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
| RoadSound.com - Tools For Bands, Stuff For Fans
| Collaborative Online Management And Syndication Tools
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
Re: header issues etc...
Posted by Perrin Harkins <pe...@elem.com>.
On 7/3/07, Jonathan Vanasco <jv...@2xlp.com> wrote:
> i prefer storing them as class variables and using a public method to
> provide access
>
> ie:
>
> package myfactory;
> my $object= object->new();
> sub get_object { return $object ;}
Using closures just makes it more confusing. Class variables are
usually implemented as globals, i.e. our $object, not my $object.
- Perrin
Re: header issues etc...
Posted by Jonathan Vanasco <jv...@2xlp.com>.
On Jul 3, 2007, at 5:51 PM, Perrin Harkins wrote:
> I don't really understand this description. If you're trying to code
> a singleton pattern, use global variables to hold the object. That
> makes it clearer what your intent is.
> Scoping works the same as usual under mod_perl. If you need access to
> object instances, you can use a singleton pattern, storing the objects
> in global variables, or you can pass the instances to the sub that
> needs to use them.
i prefer storing them as class variables and using a public method to
provide access
ie:
package myfactory;
my $object= object->new();
sub get_object { return $object ;}
my %objects= (
'a'=> object->new(),
)
sub get_object_hash { my ( $class, $flavor )= @_; return $objects
{$flavor} ;}
package myapp;
my $object= myfactory->get_object();
my $object_a= myfactory->get_object('a');
i can't remember if the $class is necessary or not. i'm responding
via my mobile :)
Re: header issues etc...
Posted by Perrin Harkins <pe...@elem.com>.
[ Please keep it on the list ]
On 7/3/07, pubert na <pu...@gmail.com> wrote:
> The app I'm working with uses this as a method for object b to retrieve the
> instance of object a, which created it.
>
> i.e. An object x, creates 4 objects, a,b,c, and d, then calls a method in
> object a. Object a needs a reference to object b so it calls
> $foo=CLASSX::getInstance() which returns $self. Object a can then call
> $foo->getObjectB and it has what it wants.
I don't really understand this description. If you're trying to code
a singleton pattern, use global variables to hold the object. That
makes it clearer what your intent is.
> Apparently this does not work at all under mod_perl. The only fix I can
> think of is passing the instantiating object as a parameter when the object
> is created. What do you guys usually do?
Scoping works the same as usual under mod_perl. If you need access to
object instances, you can use a singleton pattern, storing the objects
in global variables, or you can pass the instances to the sub that
needs to use them.
- Perrin
Re: header issues etc...
Posted by Perrin Harkins <pe...@elem.com>.
On 7/2/07, pubert na <pu...@gmail.com> wrote:
> my $self;
[...]
> sub doit{
>
> print $self->{CGI}->header;
> print "hello";
>
> }
This is bad. You're using a variable that you didn't pass to doit().
That means you're creating a closure. The sub will remember the $self
it saw when you first ran it, and it will never notice that $self
changes later. You need to pass $self to this sub as a parameter in
order to make this work.
- Perrin
Re: header issues etc...
Posted by Tyler Bird <bi...@epromo.com>.
Hi,
I jumped into the middle of this thread and it seems I am encountering a
segfault in the header just like you have described.
Could you give me an overview of your solution since I do not have your
first emails to this list.
Thanks
Tyler
pubert na wrote:
> I fixed it... apparently it not like the "return $self if defined
> $self;" ... return $class id ref $class is better form anyway...
> thanks and sorry about all the emails ;)
>
> On 7/2/07, *pubert na* <pubert314@gmail.com
> <ma...@gmail.com>> wrote:
>
> I was able to narrow down the problem I was having, and produce a
> test case for you folks. Below are two relatively self-explanatory
> files. If I navigate to test.cgi, it will appear to load the page
> properly, but if I hit the reload button a bunch of times in a
> row, the error_log will log segfaults. I pasted a sample at the
> bottom of this message. I'd appreciate any help at all.
> Obviously the issue is coming from CGI.pm's header function, which
> *should* be ok with mod_perl2. Thanks again. --Pubert
>
>
>
> ##>BEGIN FILE test.cgi<
>
> #!/usr/bin/perl
>
>
> use lib qw(/var/www/cgi-bin/);;
>
> use strict;
> use CGI;
> use testclass;
>
> my $cgi=new CGI;
>
> my $tc = testclass->new({CGI=>$cgi});
> $tc->doit();
>
>
> 1;
>
> ##>BEGIN FILE testclass.pm <http://testclass.pm><
>
> package testclass;
>
> my $self;
>
> #########################################################################################################
>
> sub new {
> #########################################################################################################
>
> # This is the
> constructor.
>
>
> my ( $class, $args ) = @_;
>
> return $self if defined $self;
>
> $self = {};
>
> bless $self, $class;
>
> $self->{CGI}=$args->{CGI};
>
> return $self;
> }
>
>
> sub doit{
>
> print $self->{CGI}->header;
> print "hello";
>
> }
>
> 1;
>
> >Begin error_log snipper<
> [Mon Jul 02 18:45:34 2007] [notice] SIGHUP received. Attempting
> to restart
> [Mon Jul 02 18:45:34 2007] [notice] Digest: generating secret for
> digest authentication ...
> [Mon Jul 02 18:45:34 2007] [notice] Digest: done
> [Mon Jul 02 18:45:34 2007] [notice] Apache/2.2.4 (Unix) DAV/2
> mod_apreq2-20051231/2.6.1 mod_perl/2.0.2 Perl/v5.8.8 configured --
> resuming normal operations
> [Mon Jul 02 18:45:39 2007] [notice] child pid 7925 exit signal
> Segmentation fault (11)
> [Mon Jul 02 18:45:39 2007] [notice] child pid 7926 exit signal
> Segmentation fault (11)
> [Mon Jul 02 18:45:39 2007] [notice] child pid 7927 exit signal
> Segmentation fault (11)
> [Mon Jul 02 18:45:40 2007] [notice] child pid 7928 exit signal
> Segmentation fault (11)
> [Mon Jul 02 18:45:40 2007] [notice] child pid 7929 exit signal
> Segmentation fault (11)
> [Mon Jul 02 18:45:40 2007] [notice] child pid 7931 exit signal
> Segmentation fault (11)
>
>
Re: header issues etc...
Posted by pubert na <pu...@gmail.com>.
I fixed it... apparently it not like the "return $self if defined $self;"
... return $class id ref $class is better form anyway... thanks and sorry
about all the emails ;)
On 7/2/07, pubert na <pu...@gmail.com> wrote:
>
> I was able to narrow down the problem I was having, and produce a test
> case for you folks. Below are two relatively self-explanatory files. If I
> navigate to test.cgi, it will appear to load the page properly, but if I
> hit the reload button a bunch of times in a row, the error_log will log
> segfaults. I pasted a sample at the bottom of this message. I'd appreciate
> any help at all. Obviously the issue is coming from CGI.pm's header
> function, which *should* be ok with mod_perl2. Thanks again. --Pubert
>
>
>
> ##>BEGIN FILE test.cgi<
>
> #!/usr/bin/perl
>
>
> use lib qw(/var/www/cgi-bin/);;
>
> use strict;
> use CGI;
> use testclass;
>
> my $cgi=new CGI;
>
> my $tc = testclass->new({CGI=>$cgi});
> $tc->doit();
>
>
> 1;
>
> ##>BEGIN FILE testclass.pm<
>
> package testclass;
>
> my $self;
>
> #########################################################################################################
>
> sub new {
> #########################################################################################################
>
> # This is the
> constructor.
>
>
> my ( $class, $args ) = @_;
>
> return $self if defined $self;
>
> $self = {};
>
> bless $self, $class;
>
> $self->{CGI}=$args->{CGI};
>
> return $self;
> }
>
>
> sub doit{
>
> print $self->{CGI}->header;
> print "hello";
>
> }
>
> 1;
>
> >Begin error_log snipper<
> [Mon Jul 02 18:45:34 2007] [notice] SIGHUP received. Attempting to
> restart
> [Mon Jul 02 18:45:34 2007] [notice] Digest: generating secret for digest
> authentication ...
> [Mon Jul 02 18:45:34 2007] [notice] Digest: done
> [Mon Jul 02 18:45:34 2007] [notice] Apache/2.2.4 (Unix) DAV/2
> mod_apreq2-20051231/2.6.1 mod_perl/2.0.2 Perl/v5.8.8 configured -- resuming
> normal operations
> [Mon Jul 02 18:45:39 2007] [notice] child pid 7925 exit signal
> Segmentation fault (11)
> [Mon Jul 02 18:45:39 2007] [notice] child pid 7926 exit signal
> Segmentation fault (11)
> [Mon Jul 02 18:45:39 2007] [notice] child pid 7927 exit signal
> Segmentation fault (11)
> [Mon Jul 02 18:45:40 2007] [notice] child pid 7928 exit signal
> Segmentation fault (11)
> [Mon Jul 02 18:45:40 2007] [notice] child pid 7929 exit signal
> Segmentation fault (11)
> [Mon Jul 02 18:45:40 2007] [notice] child pid 7931 exit signal
> Segmentation fault (11)
>
>