Jonathan Swartz
Wed, 06 Jan 2010 12:11:37 -0800
I tried this:
...
do "/home/jswartz/projects/unchained-transaction/connect.pl";
$dbh2 = dbconnect();
$dbh1->{InactiveDestroy} = 1;
$dbh2->{InactiveDestroy} = 1;
open( MAIL, "|/usr/sbin/sendmail" ) || die "Can't open";
...
but the same bug still occurs.
I wondered, too, if database handles would get destroyed when the
sendmail fork occurred. But as I understand it, open("|...") does a
fork and immediate exec(), so that Perl's destructors are not called.
Someone correct me if I'm wrong.
Jon On Jan 6, 2010, at 12:03 PM, m. allan noah wrote:
perhaps you should set InactiveDestroy true on your handle before you open the pipe to sendmail? allanOn Wed, Jan 6, 2010 at 2:50 PM, Jonathan Swartz <swa...@pobox.com> wrote:This is one of the most bizarre and specific bugs I've ever seen. I'veminimized 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 - okdbh2 - error: DBD::Sybase::db do failed: OpenClient message: LAYER = (5)ORIGIN = (3) SEVERITY = (5) NUMBER = (6) Server SANDBOX5, databaseMessage String: ct_results(): network packet layer: internal net libraryerror: Net-Library operation terminated due to disconnectOpenClient 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. (?!) Notethat 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 forksObviously, 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 (latestversions of all). httpd.conf contains: LoadModule perl_module /home/mercury/vendor/httpd/modules/mod_perl.so ServerRoot /home/jswartz/projects/unchained-transactionDocumentRoot /home/jswartz/projects/unchained-transaction/ htdocsPidFile 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-linuxuname='linux hp-lt-171-rnebel.ensenda.com 2.6.18-53.el5 #1 smp wed oct 1016: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=undefuseperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undefuse64bitint=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=1234d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12ivtype='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-- "The truth is an offense, but not a sin"