You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Erik Aronesty <ea...@gmail.com> on 2009/02/12 16:33:08 UTC

Re: WELCOME to modperl@perl.apache.org

-------------8<---------- Start Bug Report ------------8<----------
1. Problem Description:

It's well known that file-scoped lexicals don't work intuitively in
CGI programs under mod_perl.

When mod_perl calls the same CGI program twice, file-scoped lexicals
are not rebound.

Some people are aware of this, random posts to newsgroups will attest,
but this is not documented well enough.

Create a CGI as below, and run it many times, assigning different
CGI::param('foo') values to $x.
Lowering the number of children spawned in Apache will reduce the
number of times needed
to run the script in order to see the problem.

# this program sometimes prints old values for foo, but only under mod_perl!

 use CGI;
 my $x =CGI::param('foo');

 &y;

 sub y {
        print "content-type:text/plain\n\n?$x\n";
 }

People using mod_perl expect CGI programs to behave similarly to how
they did before mod_perl.

mod_perl should be *extremely* verbose in pointing this change out to
developers, as
it is *extremely* difficult to diagnose.

Alternatively, it should be fixed.  But I'm not sure how, since most
solutions involve creating
anonymous package scopes which require the recompiling and ruining of
mod_perl's speed
benefits.

Maybe there should just be a big fat warning on the top of the CGI
module and at the top of mod_perl,
"Don't use file-scoped lexicals!"  Or something like that.

2. Used Components and their Configuration:

*** mod_perl version 2.000003

*** using /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi/Apache2/BuildConfig.pm

*** Makefile.PL options:
  MP_APR_CONFIG  => /usr/bin/apr-1-config
  MP_APR_LIB     => aprext
  MP_APXS        => /usr/sbin/apxs
  MP_COMPAT_1X   => 1
  MP_GENERATE_XS => 1
  MP_LIBNAME     => mod_perl
  MP_USE_DSO     => 1


*** The httpd binary was not found


*** (apr|apu)-config linking info

 -laprutil-1 -lldap -llber -ldb-4.5 -lexpat
 -lapr-1  -lpthread -ldl



*** /usr/bin/perl -V
Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
  Platform:
    osname=linux, osvers=2.6.18-53.1.14.el5xen, archname=i386-linux-thread-multi
    uname='linux xenbuilder4.fedora.phx.redhat.com
2.6.18-53.1.14.el5xen #1 smp tue feb 19 07:33:17 est 2008 i686 i686
i386 gnulinux '
    config_args='-des -Doptimize=-O2 -g -pipe -Wall
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
--param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic
-fasynchronous-unwind-tables -Dversion=5.8.8 -Dmyhostname=localhost
-Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc.
-Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux
-Dvendorprefix=/usr -Dsiteprefix=/usr -Duseshrplib -Dusethreads
-Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db
-Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio
-Dinstallusrbinperl=n -Ubincompat5005 -Uversiononly
-Dpager=/usr/bin/less -isr -Dd_gethostent_r_proto
-Ud_endhostent_r_proto -Ud_sethostent_r_proto -Ud_endprotoent_r_proto
-Ud_setprotoent_r_proto -Ud_endservent_r_proto -Ud_setservent_r_proto
-Dinc_version_list=5.8.7 5.8.6 5.8.5 -Dscriptdir=/usr/bin'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE
-fno-strict-aliasing -pipe -Wdeclaration-after-statement
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
-I/usr/include/gdbm',
    optimize='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions
-fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386
-mtune=generic -fasynchronous-unwind-tables',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe
-Wdeclaration-after-statement -I/usr/local/include
-I/usr/include/gdbm'
    ccversion='', gccversion='4.1.2 20070925 (Red Hat 4.1.2-27)',
gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.6.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.6'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E
-Wl,-rpath,/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -g -pipe -Wall
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
--param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic
-fasynchronous-unwind-tables -L/usr/local/lib'

Characteristics of this binary (from libperl):
  Compile-time options: MULTIPLICITY PERL_IMPLICIT_CONTEXT
                        PERL_MALLOC_WRAP USE_ITHREADS USE_LARGE_FILES
                        USE_PERLIO USE_REENTRANT_API
  Built under linux
  Compiled at May  5 2008 10:33:58
  %ENV:
    PERL_LWP_USE_HTTP_10="1"
  @INC:
    /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.7/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.8
    /usr/lib/perl5/site_perl/5.8.7
    /usr/lib/perl5/site_perl/5.8.6
    /usr/lib/perl5/site_perl/5.8.5
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.7/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.8
    /usr/lib/perl5/vendor_perl/5.8.7
    /usr/lib/perl5/vendor_perl/5.8.6
    /usr/lib/perl5/vendor_perl/5.8.5
    /usr/lib/perl5/vendor_perl
    /usr/lib/perl5/5.8.8/i386-linux-thread-multi
    /usr/lib/perl5/5.8.8
    .

*** Packages of interest status:

Apache2            : -
Apache2::Request   : -
CGI                : 3.15
ExtUtils::MakeMaker: 6.30
LWP                : 5.805
mod_perl           : -
mod_perl2          : 2.000003


3. This is the core dump trace: (if you get a core dump):

  [CORE TRACE COMES HERE]

This report was generated by /usr/bin/mp2bug on Thu Feb 12 15:14:33 2009 GMT.

-------------8<---------- End Bug Report --------------8<----------

Note: Complete the rest of the details and post this bug report to
modperl <at> perl.apache.org. To subscribe to the list send an empty
email to modperl-subscribe@perl.apache.org.

Re: WELCOME to modperl@perl.apache.org

Posted by Erik Aronesty <ea...@gmail.com>.
> Variable "$x" will not stay shared at /usr/local/prefork/perl/thing.cgi line
> 10.

Yes, I foolishly looked in the per-virtual-host error log, instead of
the global error log
where the warning was placed neatly.

> which, with a quick googling of 'mod_perl variable will not stay shared',

I was busy googling "lexical variable mod perl" and "using my with
mod_perl", and
"mod_perl program works and then stops working and variable changes to
some old value".

the "not stay shared" is something I hadn't thought of.

Re: WELCOME to modperl@perl.apache.org

Posted by Adam Prime <ad...@utoronto.ca>.
Erik Aronesty wrote:
>> Maybe ModPerl::Registry should do this, but not mod_perl itself. If someone
> 
> Yes, it's a problem with ModPerl::Registry, I agree.  It's not mentioned here:
> 
> http://perl.apache.org/docs/2.0/api/ModPerl/Registry.html#Caveats
> 
> Where it should be.

Absolutely, i'll patch the docs to add a link to the perl reference page 
over the weekend.

>> is trying to get an old CGI script to work under mod_perl then they'd use
>> Registry. But there's no reason to make the rest of us suffer for their old
>> scripts.
> 
> # This isn't an "old" program...it's a simple program,
> # and no amount of "strict or warnings" will help debug it
> 
>  use CGI;
>  my $x =CGI::param('foo');
> 
>  &y;
> 
>  sub y {
>        print "content-type:text/plain\n\n?$x\n";
>  }

If you add use strict and use warnings to that script, you get this in 
your error_log:

Variable "$x" will not stay shared at /usr/local/prefork/perl/thing.cgi 
line 10.

which, with a quick googling of 'mod_perl variable will not stay 
shared', turns you to a number of resources talking about the problem, 
and it's solutions.

And for what it's worth, it seems that running under ModPerl::PerlRun 
makes it work alright, albeit with 2 warnings in the error_log:

Variable "$x" will not stay shared at /usr/local/prefork/perl/haha.cgi 
line 10.
Subroutine y redefined at /usr/local/prefork/perl/haha.cgi line 9.

Adam

Re: WELCOME to modperl@perl.apache.org

Posted by Erik Aronesty <ea...@gmail.com>.
> Maybe ModPerl::Registry should do this, but not mod_perl itself. If someone

Yes, it's a problem with ModPerl::Registry, I agree.  It's not mentioned here:

http://perl.apache.org/docs/2.0/api/ModPerl/Registry.html#Caveats

Where it should be.

> is trying to get an old CGI script to work under mod_perl then they'd use
> Registry. But there's no reason to make the rest of us suffer for their old
> scripts.

# This isn't an "old" program...it's a simple program,
# and no amount of "strict or warnings" will help debug it

 use CGI;
 my $x =CGI::param('foo');

 &y;

 sub y {
       print "content-type:text/plain\n\n?$x\n";
 }

Re: WELCOME to modperl@perl.apache.org

Posted by André Warnier <aw...@ice-sa.com>.
Michael Peters wrote:
> Erik Aronesty wrote:
> 
This can not be called "verbose", because it's rather hard to find, but 
it's worth reading.

http://perl.apache.org/docs/general/perl_reference/perl_reference.html#toc_Remedies_for_Inner_Subroutines

But normally perl/mod_perl will warn you in the logfile, whenever you do 
something of the kind, with a

Variable "$x" will not stay shared at ./nested.pl line 10


Re: WELCOME to modperl@perl.apache.org

Posted by Michael Peters <mp...@plusthree.com>.
Erik Aronesty wrote:

> mod_perl should be *extremely* verbose in pointing this change out to
> developers, as
> it is *extremely* difficult to diagnose.

Maybe ModPerl::Registry should do this, but not mod_perl itself. If someone is trying to get an old 
CGI script to work under mod_perl then they'd use Registry. But there's no reason to make the rest 
of us suffer for their old scripts.

> Alternatively, it should be fixed.  But I'm not sure how, since most
> solutions involve creating
> anonymous package scopes which require the recompiling and ruining of
> mod_perl's speed
> benefits.

No, changing your code's structure or scope is not something that should be done automatically.

> Maybe there should just be a big fat warning on the top of the CGI
> module and at the top of mod_perl,
> "Don't use file-scoped lexicals!"  Or something like that.

The problem with that is that they are useful for having things like Singleton's that don't change 
between invocations of the script (like a Conf object).

-- 
Michael Peters
Plus Three, LP