Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

[mp2] [BUG] Segfault with Test::More - duping STDOUT?

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


merlyn.kline at jobsite

Dec 6, 2011, 9:40 AM

Post #1 of 4 (579 views)
Permalink
[mp2] [BUG] Segfault with Test::More - duping STDOUT?

(I have read the bug reporting guides but unfortunately cannot follow all the instructions because I am missing Apache::TestReportPerl and do not have the necessary permissions to install it, nor to rebuild perl with debugging turned on. Hopefully I have provided enough information.)

I have discovered that simply "use"ing Test::More in a mod_perl script causes my apache to segfault. I originally reported this to the author of Test::More (see https://rt.cpan.org/Public/Bug/Display.html?id=69687) but now believe the problem to have wider scope. By progressively removing code from my original example I have reduced it to the trivial example that follows.

To REPRODUCE the problem, you need a Broken.pm module like this:

package Broken;
my $Testout;
create(); sub create { # Insert "{#" at the start of this line and the segfault goes away
open( $Testout, ">&STDOUT" ) or die "Can't dup STDOUT: $!";
}

and a script like this:

#!/usr/bin/perl -w

use Broken;

print "Content-Type: text/html\r\n\r\nhello ";
open TEST, "|/bin/cat";
close TEST;
print "world\n";

Holding down F5 to generate reloads soon causes a segfault (my server is configured for five mod_perl processes).

Note that if the code to dup STDOUT is not in a sub then the fault seems to go away.

Apache, mod_perl and perl version info appended.

I have found a similar(ish) report at http://http://stackoverflow.com/questions/4413411/ but no resolution. Note that removing from my example the code that opens the pipe to cat, solves the problem - this is the similarity here (and I realise that's likely a red herring).

Merlyn Kline






Apache/2.2.15 (Unix) DAV/2 mod_ssl/2.2.15 OpenSSL/1.0.0-fips mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations



Summary of my perl5 (revision 5 version 10 subversion 1) configuration:

Platform:
osname=linux, osvers=2.6.18-194.26.1.el5, archname=x86_64-linux-thread-multi
uname='linux x86-003.build.bos.redhat.com 2.6.18-194.26.1.el5 #1 smp fri oct 29 14:21:16 edt 2010 x86_64 x86_64 x86_64 gnulinux '
config_args='-des -Doptimize=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -DDEBUGGING=-g -Dversion=5.10.1 -Dmyhostname=localhost -Dperladmin=root [at] localhos -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl5 -Dsitearch=/usr/local/lib64/perl5 -Dprivlib=/usr/share/perl5 -Darchlib=/usr/lib64/perl5 -Dvendorlib=/usr/share/perl5/vendor_perl -Dvendorarch=/usr/lib64/perl5/vendor_perl -Dinc_version_list=5.10.0 -Darchname=x86_64-linux-thread-multi -Dlibpth=/usr/local/lib64 /lib64 /usr/lib64 -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 -Dscriptdir=/usr/bin'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic',
cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
ccversion='', gccversion='4.4.4 20100726 (Red Hat 4.4.4-13)', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='gcc', ldflags =' -fstack-protector'
libpth=/usr/local/lib64 /lib64 /usr/lib64
libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
libc=, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version='2.12'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib64/perl5/CORE'
cccdlflags='-fPIC', lddlflags='-shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'


Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV
PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP USE_64_BIT_ALL
USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES
USE_PERLIO USE_REENTRANT_API
Built under linux
Compiled at Apr 19 2011 15:27:31


bac2bac at bac2bac

Dec 7, 2011, 2:37 AM

Post #2 of 4 (550 views)
Permalink
Re: [mp2] [BUG] Segfault with Test::More - duping STDOUT? [In reply to]

Hello,

I'm unclear about your sample code, but if you did want to send the
output of say open TEST, "|/bin/cat" to the browser, your Perl version
should be configured with sfio. The information you've pasted shows that
d_sfio=undef. If you did want to do something like "/bin/cat notpasswd"
to the browser, you could use backticks: print `/bin/cat notpasswd`. As
this is handled with forking, it's not recommended for performance.

mod_perl ties STDOUT and STDIN to the Apache request (the socket from
which the request originated). STDERR is tied to the error_log.

The Test::* modules are designed to be run once from what I understand.
Invoking them repeatedly without resetting Test::* globals inside the
persistent mod_perl environment will most likely cause problems, any
combination of which could be the cause of the segfaults.

To deal with these issues, you can try Apache::Test. Pass an Apache
request to the plan method to tie STDOUT to the Apache request. The
-withtestmore tag makes Apache::Test use Test::More and not Test.pm,
which is the default functionality.

You could set up tests like this with a handler:

### TestBroken.pm ###

package TestBroken;

use strict;

# Note the hyphen before the tag.
# You don't have to 'use Test::More' here because Apache::Test
# will use it behind the scenes for you.
use Apache::Test qw(-withtestmore);

use Apache2::RequestRec ();
use Apache2::Const -compile => qw(OK);

use Broken; # Where you set up tests

sub handler{

my $r = shift;

plan $r, tests => 3; # Pass $r to plan

is_bigger( 2, 1, '2 is > 1' );
is_bigger( 20, 10, '20 is > 10' );
is_bigger( 10, 100, '10 is !> 100' );

return Apache2::Const::OK;
}

1;

### end TestBroken.pm ###


### Broken.pm ###

package Broken;
use strict;
use base 'Exporter';

our @EXPORT = qw( is_bigger );

use Test::Builder;

our $Test = Test::Builder->create();

sub is_bigger($$;$){
my ( $first_num, $second_num, $dsc ) = @_;

return (
$Test->ok( "$first_num" > "$second_num", $dsc ) ||
$Test->diag(" $first_num is not bigger than $second_num ")
);
}

1;

### End Broken.pm ###


Another option is to 'use Test::More' explicitly:
(Do note that I have managed to segfault this)

use Apache::Test qw(:withtestmore);
use Test::More;


And finally, if it works for you, to use Test.pm and not Test::More with
just
use Apache::Test

There're a few tricky details in each case and there's no guarantee
about full Test::More functionality so be aware:
http://search.cpan.org/~phred/mod_perl-2.0.5/Apache-Test/lib/Apache/Test.pm

g.


On 12/6/2011 9:40 AM, Merlyn Kline wrote:
>
> (I have read the bug reporting guides but unfortunately cannot follow all the instructions because I am missing Apache::TestReportPerl and do not have the necessary permissions to install it, nor to rebuild perl with debugging turned on. Hopefully I have provided enough information.)
>
> I have discovered that simply "use"ing Test::More in a mod_perl script causes my apache to segfault. I originally reported this to the author of Test::More (see https://rt.cpan.org/Public/Bug/Display.html?id=69687) but now believe the problem to have wider scope. By progressively removing code from my original example I have reduced it to the trivial example that follows.
>
> To REPRODUCE the problem, you need a Broken.pm module like this:
>
> package Broken;
> my $Testout;
> create(); sub create { # Insert "{#" at the start of this line and the segfault goes away
> open( $Testout, ">&STDOUT" ) or die "Can't dup STDOUT: $!";
> }
>
> and a script like this:
>
> #!/usr/bin/perl -w
>
> use Broken;
>
> print "Content-Type: text/html\r\n\r\nhello ";
> open TEST, "|/bin/cat";
> close TEST;
> print "world\n";
>
> Holding down F5 to generate reloads soon causes a segfault (my server is configured for five mod_perl processes).
>
> Note that if the code to dup STDOUT is not in a sub then the fault seems to go away.
>
> Apache, mod_perl and perl version info appended.
>
> I have found a similar(ish) report at http://http://stackoverflow.com/questions/4413411/ but no resolution. Note that removing from my example the code that opens the pipe to cat, solves the problem - this is the similarity here (and I realise that's likely a red herring).
>
> Merlyn Kline
>
>
>
>
>
>
> Apache/2.2.15 (Unix) DAV/2 mod_ssl/2.2.15 OpenSSL/1.0.0-fips mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
>
>
>
> Summary of my perl5 (revision 5 version 10 subversion 1) configuration:
>
> Platform:
> osname=linux, osvers=2.6.18-194.26.1.el5, archname=x86_64-linux-thread-multi
> uname='linux x86-003.build.bos.redhat.com 2.6.18-194.26.1.el5 #1 smp fri oct 29 14:21:16 edt 2010 x86_64 x86_64 x86_64 gnulinux '
> config_args='-des -Doptimize=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -DDEBUGGING=-g -Dversion=5.10.1 -Dmyhostname=localhost -Dperladmin=root [at] localhos -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl5 -Dsitearch=/usr/local/lib64/perl5 -Dprivlib=/usr/share/perl5 -Darchlib=/usr/lib64/perl5 -Dvendorlib=/usr/share/perl5/vendor_perl -Dvendorarch=/usr/lib64/perl5/vendor_perl -Dinc_version_list=5.10.0 -Darchname=x86_64-linux-thread-multi -Dlibpth=/usr/local/lib64 /lib64 /usr/lib64 -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_prot
o -Ud_endservent_r_proto -Ud_setservent_r_proto -Dscriptdir=/usr/bin'
> hint=recommended, useposix=true, d_sigaction=define
> useithreads=define, usemultiplicity=define
> useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
> use64bitint=define, use64bitall=define, uselongdouble=undef
> usemymalloc=n, bincompat5005=undef
> Compiler:
> cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
> optimize='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic',
> cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
> ccversion='', gccversion='4.4.4 20100726 (Red Hat 4.4.4-13)', gccosandvers=''
> intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
> d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
> ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
> alignbytes=8, prototype=define
> Linker and Libraries:
> ld='gcc', ldflags =' -fstack-protector'
> libpth=/usr/local/lib64 /lib64 /usr/lib64
> libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
> perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
> libc=, so=so, useshrplib=true, libperl=libperl.so
> gnulibc_version='2.12'
> Dynamic Linking:
> dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib64/perl5/CORE'
> cccdlflags='-fPIC', lddlflags='-shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'
>
>
> Characteristics of this binary (from libperl):
> Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV
> PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP USE_64_BIT_ALL
> USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES
> USE_PERLIO USE_REENTRANT_API
> Built under linux
> Compiled at Apr 19 2011 15:27:31
>
>
>


torsten.foertsch at gmx

Dec 7, 2011, 4:23 AM

Post #3 of 4 (524 views)
Permalink
Re: [mp2] [BUG] Segfault with Test::More - duping STDOUT? [In reply to]

On Wednesday, 07 December 2011 02:37:19 gAzZaLi wrote:
> Another option is to 'use Test::More' explicitly:
> (Do note that I have managed to segfault this)
>
> use Apache::Test qw(:withtestmore);
> use Test::More;

As of Apache::Test 1.35++ this is wrong. Sorry about the interface change. The
point is, up to 1.35 it was not possible to use Apache::Test with and without
Test::More in the same interpreter. Now, if you "use Apache::Test" it marks
the caller package to run without Test::More (it uses Test.pm instead). If you
"use Apache::Test '-withtestmore'" the package is marked to use Test::More.

Unfortunately, Test.pm based tests and Test::Builder based tests are
incompatible. One cannot use Test::(ok|plan|whatever) and Test::More::(ok|
plan|whatever) in the same interpreter. That's the source of the problem.
Normally, when Test or Test::More is used in *.t files that does not matter.
But with server based tests in modperl they must work in the same interpreter.

Torsten Förtsch

--
Need professional modperl support? Hire me! (http://foertsch.name)

Like fantasy? http://kabatinte.net


torsten.foertsch at gmx

Dec 7, 2011, 4:33 AM

Post #4 of 4 (523 views)
Permalink
Re: [mp2] [BUG] Segfault with Test::More - duping STDOUT? [In reply to]

On Tuesday, 06 December 2011 17:40:14 Merlyn Kline wrote:
> To REPRODUCE the problem, you need a Broken.pm module like this:
>
> package Broken;
> my $Testout;
> create(); sub create { # Insert "{#" at the start of this line and the
> segfault goes away open( $Testout, ">&STDOUT" ) or die "Can't dup
> STDOUT: $!"; }
>
> and a script like this:
>
> #!/usr/bin/perl -w
>
> use Broken;
>
> print "Content-Type: text/html\r\n\r\nhello ";
> open TEST, "|/bin/cat";
> close TEST;
> print "world\n";
>
> Holding down F5 to generate reloads soon causes a segfault (my server is
> configured for five mod_perl processes).
>
> Note that if the code to dup STDOUT is not in a sub then the fault seems to
> go away.

Can you reproduce the bug with modperl 2.0.5 or above (trunk)? There is a bug
that has been fixed in 2.0.5 that could course this behavior (I guess).

see http://svn.apache.org/viewvc?view=revision&revision=932875

Torsten Förtsch

--
Need professional modperl support? Hire me! (http://foertsch.name)

Like fantasy? http://kabatinte.net

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.