On Mon, Feb 25, 2002 at 05:13:41PM +0200, Andrejs Dubovskis wrote:
> Hi,
>
> when trying to pass dbh handle to child after fork I have found that
> parent still has opened unix sockets. Very simple program to reproduce
> this problem provided.
> Program in loop (3 times) opens DBI connection and forks.
> Parent set InactiveDestroy before handle destroying.
> While program is running I have run lsof (output attached).
> You can see following:
> parent have 3 unix socket;
> child 1230 have 1 unix socket;
> child 1232 have 2 unix socket;
> child 1234 have 3 unix socket;
> Looks, when perl destroys object, it does not close unix socket.
For InactiveDestroy read "Ineffective DESTROY".
All it does is turn off $h->{Active} before calling DESTROY.
> =============================================
> Possible solution
> =============================================
> when destroying dbi handle DBD::Pg calls PQfinish function.
> PQfinish contains two calls:
> closePGconn - sends disconect to backend;
> freePGconn - free resources (close socket as well);
>
> So, in case of InactiveDestroy DBD::Pg have to call freePGconn
> in DESTROY and PQfinish otherwise.
It would seem reasonable for the closePGconn to be skipped
if Active is off (and if disconnect() calls closePGconn).
Tim.
> =============================================
> environment
> =============================================
> redhat 7.1
> linux 2.4.16
> DBI 1.20
> DBD::Pg 1.01
> postgres 7.1.3
>
> Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
> Platform:
> osname=linux, osvers=2.4.9, archname=i386-linux
> uname='linux host 2.4.9 #4 smp mon sep 17 20:17:53 eest 2001 i686
> unknown '
> config_args='-des -Doptimize=-O2 -march=i386 -mcpu=i686 -Dcc=gcc
> -Dcccdlflags=-fPIC -Dinstallprefix=/usr -Dprefix=/usr
> -Darchname=i386-linux -Dd_dosuid -Dd_semctl_semun -Ui_db -Ui_ndbm
> -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Uuselargefiles'
> hint=recommended, useposix=true, d_sigaction=define
> usethreads=undef use5005threads=undef useithreads=undef
> usemultiplicity=undef
> useperlio=undef d_sfio=undef uselargefiles=undef usesocks=undef
> use64bitint=undef use64bitall=undef uselongdouble=undef
> Compiler:
> cc='gcc', ccflags ='-fno-strict-aliasing',
> optimize='-O2 -march=i386 -mcpu=i686',
> cppflags='-fno-strict-aliasing'
> ccversion='', gccversion='2.96 20000731 (Red Hat Linux 7.1
> 2.96-85)', 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=4
> alignbytes=4, usemymalloc=n, prototype=define
> Linker and Libraries:
> ld='gcc', ldflags =' -L/usr/local/lib'
> libpth=/usr/local/lib /lib /usr/lib
> libs=-lnsl -ldl -lm -lc -lcrypt -lutil
> perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil
> libc=/lib/libc-2.2.2.so, so=so, useshrplib=false, libperl=libperl.a
> Dynamic Linking:
> dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
> cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'
>
>
> Characteristics of this binary (from libperl):
> Compile-time options:
> Built under linux
> Compiled at Sep 18 2001 15:45:22
> %ENV:
> PERL5LIB="/home/andrejs/lib"
> @INC:
> /home/andrejs/lib
> /usr/lib/perl5/5.6.1/i386-linux
> /usr/lib/perl5/5.6.1
> /usr/lib/perl5/site_perl/5.6.1/i386-linux
> /usr/lib/perl5/site_perl/5.6.1
> /usr/lib/perl5/site_perl
>
> =============================================
> test program
> =============================================
> [andrejs@host tmp]$ cat testpg.pl
> #!/usr/bin/perl -w
>
> use DBI ;
>
> $|++ ; # disable stdout buffering
>
> for (1..3) {
> my $dbh = DBI->connect("DBI:Pg:dbname=test", "test", "") or die ;
>
> if (fork) {
> # parent
> $dbh->{InactiveDestroy} = 1 ;
> } else {
> # child
> print "child $$ going to sleep\n" ;
> sleep 20 ;
> exit ;
> }
> }
> print "parent $$ going to sleep\n" ;
>
> sleep 20 ;
>
>
> =============================================
> run
> =============================================
> [andrejs@host tmp]$ ./testpg.pl &
> [1] 1228
>
> [andrejs@host tmp]$ child 1230 going to sleep
> child 1232 going to sleep
> child 1234 going to sleep
> parent 1228 going to sleep
>
> =============================================
> lsof
> =============================================
> [andrejs@host tmp]$ /usr/sbin/lsof | grep ^testpg
> testpg.pl 1228 andrejs cwd DIR 8,5 4096 16232
> /home/andrejs/tmp
> testpg.pl 1228 andrejs rtd DIR 8,1 4096 2 /
> testpg.pl 1228 andrejs txt REG 8,1 740284 370595
> /usr/bin/perl
> testpg.pl 1228 andrejs mem REG 8,1 471781 176763
> /lib/ld-2.2.2.so
> testpg.pl 1228 andrejs mem REG 8,1 244 497998
> /usr/lib/locale/en_US/LC_IDENTIFICATION
> testpg.pl 1228 andrejs mem REG 8,1 13 497999
> /usr/lib/locale/en_US/LC_MEASUREMENT
> testpg.pl 1228 andrejs mem REG 8,1 49 498002
> /usr/lib/locale/en_US/LC_TELEPHONE
> testpg.pl 1228 andrejs mem REG 8,1 145 497997
> /usr/lib/locale/en_US/LC_ADDRESS
> testpg.pl 1228 andrejs mem REG 8,1 67 498000
> /usr/lib/locale/en_US/LC_NAME
> testpg.pl 1228 andrejs mem REG 8,1 445289 176781
> /lib/libnsl-2.2.2.so
> testpg.pl 1228 andrejs mem REG 8,1 79024 176776
> /lib/libdl-2.2.2.so
> testpg.pl 1228 andrejs mem REG 8,1 627312 481968
> /lib/i686/libm-2.2.2.so
> testpg.pl 1228 andrejs mem REG 8,1 5634864 481966
> /lib/i686/libc-2.2.2.so
> testpg.pl 1228 andrejs mem REG 8,1 95362 176774
> /lib/libcrypt-2.2.2.so
> testpg.pl 1228 andrejs mem REG 8,1 61451 176816
> /lib/libutil-2.2.2.so
> testpg.pl 1228 andrejs mem REG 8,1 24 498001
> /usr/lib/locale/en_US/LC_PAPER
> testpg.pl 1228 andrejs mem REG 8,1 42 16096
> /usr/lib/locale/en_US/LC_MESSAGES/SYS_LC_MESSAGES
> testpg.pl 1228 andrejs mem REG 8,1 276 32149
> /usr/lib/locale/en_US/LC_MONETARY
> testpg.pl 1228 andrejs mem REG 8,1 21484 224928
> /usr/lib/locale/en_US/LC_COLLATE
> testpg.pl 1228 andrejs mem REG 8,1 2441 498003
> /usr/lib/locale/en_US/LC_TIME
> testpg.pl 1228 andrejs mem REG 8,1 44 224924
> /usr/lib/locale/en_US/LC_NUMERIC
> testpg.pl 1228 andrejs mem REG 8,1 110304 385570
> /usr/lib/locale/en_US/LC_CTYPE
> testpg.pl 1228 andrejs mem REG 8,1 68999 337730
> /usr/lib/perl5/site_perl/5.6.1/i386-linux/auto/DBI/DBI.so
> testpg.pl 1228 andrejs mem REG 8,1 95114 81673
> /usr/lib/perl5/5.6.1/i386-linux/auto/POSIX/POSIX.so
> testpg.pl 1228 andrejs mem REG 8,1 55554 627982
> /usr/lib/perl5/site_perl/5.6.1/i386-linux/auto/DBD/Pg/Pg.so
> testpg.pl 1228 andrejs mem REG 8,1 76472 386571
> /usr/lib/libpq.so.2.1
> testpg.pl 1228 andrejs mem REG 8,1 203467 386560
> /usr/lib/libssl.so.0.9.6
> testpg.pl 1228 andrejs mem REG 8,1 872656 386559
> /usr/lib/libcrypto.so.0.9.6
> testpg.pl 1228 andrejs mem REG 8,1 426613 578572
> /usr/kerberos/lib/libkrb5.so.3.0
> testpg.pl 1228 andrejs mem REG 8,1 78257 578570
> /usr/kerberos/lib/libk5crypto.so.3.0
> testpg.pl 1228 andrejs mem REG 8,1 8681 578568
> /usr/kerberos/lib/libcom_err.so.3.0
> testpg.pl 1228 andrejs mem REG 8,1 274054 176810
> /lib/libresolv-2.2.2.so
> testpg.pl 1228 andrejs 0u CHR 136,6 8
> /dev/pts/6
> testpg.pl 1228 andrejs 1u CHR 136,6 8
> /dev/pts/6
> testpg.pl 1228 andrejs 2u CHR 136,6 8
> /dev/pts/6
> testpg.pl 1228 andrejs 3u unix 0xc33a2f60 39562840 socket
> testpg.pl 1228 andrejs 4u unix 0xdfa69ae0 39562842 socket
> testpg.pl 1228 andrejs 5u unix 0xc33a28e0 39562844 socket
> testpg.pl 1230 andrejs cwd DIR 8,5 4096 16232
> /home/andrejs/tmp
> testpg.pl 1230 andrejs rtd DIR 8,1 4096 2 /
> testpg.pl 1230 andrejs txt REG 8,1 740284 370595
> /usr/bin/perl
> testpg.pl 1230 andrejs mem REG 8,1 471781 176763
> /lib/ld-2.2.2.so
> testpg.pl 1230 andrejs mem REG 8,1 244 497998
> /usr/lib/locale/en_US/LC_IDENTIFICATION
> testpg.pl 1230 andrejs mem REG 8,1 13 497999
> /usr/lib/locale/en_US/LC_MEASUREMENT
> testpg.pl 1230 andrejs mem REG 8,1 49 498002
> /usr/lib/locale/en_US/LC_TELEPHONE
> testpg.pl 1230 andrejs mem REG 8,1 145 497997
> /usr/lib/locale/en_US/LC_ADDRESS
> testpg.pl 1230 andrejs mem REG 8,1 67 498000
> /usr/lib/locale/en_US/LC_NAME
> testpg.pl 1230 andrejs mem REG 8,1 445289 176781
> /lib/libnsl-2.2.2.so
> testpg.pl 1230 andrejs mem REG 8,1 79024 176776
> /lib/libdl-2.2.2.so
> testpg.pl 1230 andrejs mem REG 8,1 627312 481968
> /lib/i686/libm-2.2.2.so
> testpg.pl 1230 andrejs mem REG 8,1 5634864 481966
> /lib/i686/libc-2.2.2.so
> testpg.pl 1230 andrejs mem REG 8,1 95362 176774
> /lib/libcrypt-2.2.2.so
> testpg.pl 1230 andrejs mem REG 8,1 61451 176816
> /lib/libutil-2.2.2.so
> testpg.pl 1230 andrejs mem REG 8,1 24 498001
> /usr/lib/locale/en_US/LC_PAPER
> testpg.pl 1230 andrejs mem REG 8,1 42 16096
> /usr/lib/locale/en_US/LC_MESSAGES/SYS_LC_MESSAGES
> testpg.pl 1230 andrejs mem REG 8,1 276 32149
> /usr/lib/locale/en_US/LC_MONETARY
> testpg.pl 1230 andrejs mem REG 8,1 21484 224928
> /usr/lib/locale/en_US/LC_COLLATE
> testpg.pl 1230 andrejs mem REG 8,1 2441 498003
> /usr/lib/locale/en_US/LC_TIME
> testpg.pl 1230 andrejs mem REG 8,1 44 224924
> /usr/lib/locale/en_US/LC_NUMERIC
> testpg.pl 1230 andrejs mem REG 8,1 110304 385570
> /usr/lib/locale/en_US/LC_CTYPE
> testpg.pl 1230 andrejs mem REG 8,1 68999 337730
> /usr/lib/perl5/site_perl/5.6.1/i386-linux/auto/DBI/DBI.so
> testpg.pl 1230 andrejs mem REG 8,1 95114 81673
> /usr/lib/perl5/5.6.1/i386-linux/auto/POSIX/POSIX.so
> testpg.pl 1230 andrejs mem REG 8,1 55554 627982
> /usr/lib/perl5/site_perl/5.6.1/i386-linux/auto/DBD/Pg/Pg.so
> testpg.pl 1230 andrejs mem REG 8,1 76472 386571
> /usr/lib/libpq.so.2.1
> testpg.pl 1230 andrejs mem REG 8,1 203467 386560
> /usr/lib/libssl.so.0.9.6
> testpg.pl 1230 andrejs mem REG 8,1 872656 386559
> /usr/lib/libcrypto.so.0.9.6
> testpg.pl 1230 andrejs mem REG 8,1 426613 578572
> /usr/kerberos/lib/libkrb5.so.3.0
> testpg.pl 1230 andrejs mem REG 8,1 78257 578570
> /usr/kerberos/lib/libk5crypto.so.3.0
> testpg.pl 1230 andrejs mem REG 8,1 8681 578568
> /usr/kerberos/lib/libcom_err.so.3.0
> testpg.pl 1230 andrejs mem REG 8,1 274054 176810
> /lib/libresolv-2.2.2.so
> testpg.pl 1230 andrejs 0u CHR 136,6 8
> /dev/pts/6
> testpg.pl 1230 andrejs 1u CHR 136,6 8
> /dev/pts/6
> testpg.pl 1230 andrejs 2u CHR 136,6 8
> /dev/pts/6
> testpg.pl 1230 andrejs 3u unix 0xc33a2f60 39562840 socket
> testpg.pl 1232 andrejs cwd DIR 8,5 4096 16232
> /home/andrejs/tmp
> testpg.pl 1232 andrejs rtd DIR 8,1 4096 2 /
> testpg.pl 1232 andrejs txt REG 8,1 740284 370595
> /usr/bin/perl
> testpg.pl 1232 andrejs mem REG 8,1 471781 176763
> /lib/ld-2.2.2.so
> testpg.pl 1232 andrejs mem REG 8,1 244 497998
> /usr/lib/locale/en_US/LC_IDENTIFICATION
> testpg.pl 1232 andrejs mem REG 8,1 13 497999
> /usr/lib/locale/en_US/LC_MEASUREMENT
> testpg.pl 1232 andrejs mem REG 8,1 49 498002
> /usr/lib/locale/en_US/LC_TELEPHONE
> testpg.pl 1232 andrejs mem REG 8,1 145 497997
> /usr/lib/locale/en_US/LC_ADDRESS
> testpg.pl 1232 andrejs mem REG 8,1 67 498000
> /usr/lib/locale/en_US/LC_NAME
> testpg.pl 1232 andrejs mem REG 8,1 445289 176781
> /lib/libnsl-2.2.2.so
> testpg.pl 1232 andrejs mem REG 8,1 79024 176776
> /lib/libdl-2.2.2.so
> testpg.pl 1232 andrejs mem REG 8,1 627312 481968
> /lib/i686/libm-2.2.2.so
> testpg.pl 1232 andrejs mem REG 8,1 5634864 481966
> /lib/i686/libc-2.2.2.so
> testpg.pl 1232 andrejs mem REG 8,1 95362 176774
> /lib/libcrypt-2.2.2.so
> testpg.pl 1232 andrejs mem REG 8,1 61451 176816
> /lib/libutil-2.2.2.so
> testpg.pl 1232 andrejs mem REG 8,1 24 498001
> /usr/lib/locale/en_US/LC_PAPER
> testpg.pl 1232 andrejs mem REG 8,1 42 16096
> /usr/lib/locale/en_US/LC_MESSAGES/SYS_LC_MESSAGES
> testpg.pl 1232 andrejs mem REG 8,1 276 32149
> /usr/lib/locale/en_US/LC_MONETARY
> testpg.pl 1232 andrejs mem REG 8,1 21484 224928
> /usr/lib/locale/en_US/LC_COLLATE
> testpg.pl 1232 andrejs mem REG 8,1 2441 498003
> /usr/lib/locale/en_US/LC_TIME
> testpg.pl 1232 andrejs mem REG 8,1 44 224924
> /usr/lib/locale/en_US/LC_NUMERIC
> testpg.pl 1232 andrejs mem REG 8,1 110304 385570
> /usr/lib/locale/en_US/LC_CTYPE
> testpg.pl 1232 andrejs mem REG 8,1 68999 337730
> /usr/lib/perl5/site_perl/5.6.1/i386-linux/auto/DBI/DBI.so
> testpg.pl 1232 andrejs mem REG 8,1 95114 81673
> /usr/lib/perl5/5.6.1/i386-linux/auto/POSIX/POSIX.so
> testpg.pl 1232 andrejs mem REG 8,1 55554 627982
> /usr/lib/perl5/site_perl/5.6.1/i386-linux/auto/DBD/Pg/Pg.so
> testpg.pl 1232 andrejs mem REG 8,1 76472 386571
> /usr/lib/libpq.so.2.1
> testpg.pl 1232 andrejs mem REG 8,1 203467 386560
> /usr/lib/libssl.so.0.9.6
> testpg.pl 1232 andrejs mem REG 8,1 872656 386559
> /usr/lib/libcrypto.so.0.9.6
> testpg.pl 1232 andrejs mem REG 8,1 426613 578572
> /usr/kerberos/lib/libkrb5.so.3.0
> testpg.pl 1232 andrejs mem REG 8,1 78257 578570
> /usr/kerberos/lib/libk5crypto.so.3.0
> testpg.pl 1232 andrejs mem REG 8,1 8681 578568
> /usr/kerberos/lib/libcom_err.so.3.0
> testpg.pl 1232 andrejs mem REG 8,1 274054 176810
> /lib/libresolv-2.2.2.so
> testpg.pl 1232 andrejs 0u CHR 136,6 8
> /dev/pts/6
> testpg.pl 1232 andrejs 1u CHR 136,6 8
> /dev/pts/6
> testpg.pl 1232 andrejs 2u CHR 136,6 8
> /dev/pts/6
> testpg.pl 1232 andrejs 3u unix 0xc33a2f60 39562840 socket
> testpg.pl 1232 andrejs 4u unix 0xdfa69ae0 39562842 socket
> testpg.pl 1234 andrejs cwd DIR 8,5 4096 16232
> /home/andrejs/tmp
> testpg.pl 1234 andrejs rtd DIR 8,1 4096 2 /
> testpg.pl 1234 andrejs txt REG 8,1 740284 370595
> /usr/bin/perl
> testpg.pl 1234 andrejs mem REG 8,1 471781 176763
> /lib/ld-2.2.2.so
> testpg.pl 1234 andrejs mem REG 8,1 244 497998
> /usr/lib/locale/en_US/LC_IDENTIFICATION
> testpg.pl 1234 andrejs mem REG 8,1 13 497999
> /usr/lib/locale/en_US/LC_MEASUREMENT
> testpg.pl 1234 andrejs mem REG 8,1 49 498002
> /usr/lib/locale/en_US/LC_TELEPHONE
> testpg.pl 1234 andrejs mem REG 8,1 145 497997
> /usr/lib/locale/en_US/LC_ADDRESS
> testpg.pl 1234 andrejs mem REG 8,1 67 498000
> /usr/lib/locale/en_US/LC_NAME
> testpg.pl 1234 andrejs mem REG 8,1 445289 176781
> /lib/libnsl-2.2.2.so
> testpg.pl 1234 andrejs mem REG 8,1 79024 176776
> /lib/libdl-2.2.2.so
> testpg.pl 1234 andrejs mem REG 8,1 627312 481968
> /lib/i686/libm-2.2.2.so
> testpg.pl 1234 andrejs mem REG 8,1 5634864 481966
> /lib/i686/libc-2.2.2.so
> testpg.pl 1234 andrejs mem REG 8,1 95362 176774
> /lib/libcrypt-2.2.2.so
> testpg.pl 1234 andrejs mem REG 8,1 61451 176816
> /lib/libutil-2.2.2.so
> testpg.pl 1234 andrejs mem REG 8,1 24 498001
> /usr/lib/locale/en_US/LC_PAPER
> testpg.pl 1234 andrejs mem REG 8,1 42 16096
> /usr/lib/locale/en_US/LC_MESSAGES/SYS_LC_MESSAGES
> testpg.pl 1234 andrejs mem REG 8,1 276 32149
> /usr/lib/locale/en_US/LC_MONETARY
> testpg.pl 1234 andrejs mem REG 8,1 21484 224928
> /usr/lib/locale/en_US/LC_COLLATE
> testpg.pl 1234 andrejs mem REG 8,1 2441 498003
> /usr/lib/locale/en_US/LC_TIME
> testpg.pl 1234 andrejs mem REG 8,1 44 224924
> /usr/lib/locale/en_US/LC_NUMERIC
> testpg.pl 1234 andrejs mem REG 8,1 110304 385570
> /usr/lib/locale/en_US/LC_CTYPE
> testpg.pl 1234 andrejs mem REG 8,1 68999 337730
> /usr/lib/perl5/site_perl/5.6.1/i386-linux/auto/DBI/DBI.so
> testpg.pl 1234 andrejs mem REG 8,1 95114 81673
> /usr/lib/perl5/5.6.1/i386-linux/auto/POSIX/POSIX.so
> testpg.pl 1234 andrejs mem REG 8,1 55554 627982
> /usr/lib/perl5/site_perl/5.6.1/i386-linux/auto/DBD/Pg/Pg.so
> testpg.pl 1234 andrejs mem REG 8,1 76472 386571
> /usr/lib/libpq.so.2.1
> testpg.pl 1234 andrejs mem REG 8,1 203467 386560
> /usr/lib/libssl.so.0.9.6
> testpg.pl 1234 andrejs mem REG 8,1 872656 386559
> /usr/lib/libcrypto.so.0.9.6
> testpg.pl 1234 andrejs mem REG 8,1 426613 578572
> /usr/kerberos/lib/libkrb5.so.3.0
> testpg.pl 1234 andrejs mem REG 8,1 78257 578570
> /usr/kerberos/lib/libk5crypto.so.3.0
> testpg.pl 1234 andrejs mem REG 8,1 8681 578568
> /usr/kerberos/lib/libcom_err.so.3.0
> testpg.pl 1234 andrejs mem REG 8,1 274054 176810
> /lib/libresolv-2.2.2.so
> testpg.pl 1234 andrejs 0u CHR 136,6 8
> /dev/pts/6
> testpg.pl 1234 andrejs 1u CHR 136,6 8
> /dev/pts/6
> testpg.pl 1234 andrejs 2u CHR 136,6 8
> /dev/pts/6
> testpg.pl 1234 andrejs 3u unix 0xc33a2f60 39562840 socket
> testpg.pl 1234 andrejs 4u unix 0xdfa69ae0 39562842 socket
> testpg.pl 1234 andrejs 5u unix 0xc33a28e0 39562844 socket