This is one of the most bizarre and specific bugs I've ever seen.
I've
minimized it as much as I can. Please bear with me. :)
Here is my mod_perl handler:
package Handler;
use DBI;
use strict;
use warnings;
our ($dbh1, $dbh2);
sub dbconnect {
return DBI->connect( 'DBI:Sybase:...', '...', '...',
{ RaiseError => 1
} );
}
sub testdb {
my ( $name, $dbh ) = @_;
eval { $dbh->do("select 1") };
print "$name - " . ($@ ? "error: $@" : "ok") . "\n";
}
sub handler {
my ($r) = @_;
# connect.pl contains one line: BEGIN { $Handler::dbh1 =
Handler::dbconnect() }
do "/home/jswartz/projects/unchained-transaction/connect.pl";
$dbh2 = dbconnect();
open( MAIL, "|/usr/sbin/sendmail" ) || die "Can't open";
testdb("dbh1", $dbh1);
testdb("dbh2", $dbh2);
close(MAIL);
testdb("dbh1", $dbh1);
testdb("dbh2", $dbh2);
return 0;
}
1;
When I hit / on this server, it outputs:
dbh1 - ok
dbh2 - ok
dbh1 - ok
dbh2 - error: DBD::Sybase::db do failed: OpenClient message:
LAYER = (5)
ORIGIN = (3) SEVERITY = (5) NUMBER = (6)
Server SANDBOX5, database
Message String: ct_results(): network packet layer: internal net
library
error: Net-Library operation terminated due to disconnect
OpenClient message: LAYER = (1) ORIGIN = (1) SEVERITY = (1)
NUMBER = (50)
Server SANDBOX5, database
Message String: ct_cmd_drop(): user api layer: external error: The
connection has been marked dead.
That is, $dbh2 goes "bad" when the pipe to sendmail is closed. (?!)
Note
that ping() still returns 1, I have to call do() to get the error.
Just about everything here is necessary to generate the bug. In
particular,
I cannot generate the bug...
* If I move the code from connect.pl into the handler, even as a
string eval
* If I remove the "BEGIN" from connect.pl
* If I replace sendmail with another program
* If I run this in a script outside of mod_perl - even a script
that forks
Obviously, I can change around our current code base to not hit this
particular condition, but that gives me no confidence that it won't
accidentally arise again, in this or another form.
Any advice on how to proceed appreciated!
Thanks
Jon
--------------
Using perl 5.10.1, DBI 1.609 , DBD::Sybase 1.09, Apache 2.2.14
(latest
versions of all).
httpd.conf contains:
LoadModule perl_module /home/mercury/vendor/httpd/modules/mod_perl.so
ServerRoot /home/jswartz/projects/unchained-transaction
DocumentRoot /home/jswartz/projects/unchained-transaction/
htdocs
PidFile logs/httpd.pid
TypesConfig conf/mime.types
MinSpareServers 2
MaxSpareServers 3
StartServers 2
MaxClients 4
MaxRequestsPerChild 100
PerlPostConfigRequire
/home/jswartz/projects/unchained-transaction/conf/startup.pl
Listen 3010
<Location />
SetHandler perl-script
PerlHandler Handler
</Location>
Summary of my perl5 (revision 5 version 10 subversion 1)
configuration:
Platform:
osname=linux, osvers=2.6.18-53.el5, archname=i686-linux
uname='linux hp-lt-171-rnebel.ensenda.com 2.6.18-53.el5 #1 smp
wed oct 10
16:34:02 edt 2007 i686 i686 i386 gnulinux '
config_args='-des -Uusethreads -Dprefix=/home/mercury/vendor/perl'
hint=recommended, useposix=true, d_sigaction=define
useithreads=undef, usemultiplicity=undef
useperlio=define, d_sfio=undef, uselargefiles=define,
usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_B\
ITS=64',
optimize='-O2',
cppflags='-fno-strict-aliasing -pipe -fstack-protector
-I/usr/local/include'
ccversion='', gccversion='4.1.2 20070626 (Red Hat 4.1.2-14)',
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='cc', ldflags =' -fstack-protector -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
libc=/lib/libc-2.5.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.5'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib
-fstack-protector'
Characteristics of this binary (from libperl):
Compile-time options: PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP
USE_LARGE_FILES USE_PERLIO
Built under linux
Compiled at Nov 20 2009 15:56:22