From: bty at requesttech dot com
Operating system: RedHat 9
PHP version: 4.3.4
PHP Bug Type: PostgreSQL related
Bug description: Failed pg_connect leaves Network Socket in CLOSE_WAIT State
Description:
------------
When a database connection to postgres fails the assocaited socket is not
closed by PHP but kept in a CLOSE_WAIT state. When doing a tcpdump if the
PostgreSQL sends a FIN first the final FIN packet is not Sent by PHP
leaving the socket in CLOSE_WAIT.
I have checked bug reports 9252 and 16356.
This IS PHPs problem as it does not correctly send the FIN packet
(probably a if( GOT_FIN ) close( socket ) missing from the code) when the
PostgreSQL server (or any service) sends FIN first.
This is a serious issue as the only way to remove the CLOSE_WAIT sockets
is to restart the web server. It is obvious that PHP is not doing
something correct.
Reproduce code:
---------------
$resource_id = pg_connect( "host=good dbname=good user=good password=good"
);
pg_close( $resource_id );
//This will put the socket in a TIME_WAIT state and will
//close in a matter of minutes
for( $i=0; $i < 1024; $i++ ) {
$resource_id = pg_connect( "host=good dbname=good user=good password=bad"
);
if( $resource_id )
pg_close( $resource_id );
}
//Towards the end of this loop, connections will be refused
//because too many sockets are open.
//The sockets remain in the CLOSE_WAIT state until the web
//server is rebooted
Expected result:
----------------
Sockets are closed by the final sending of a FIN packet from PHP.
Actual result:
--------------
Sockets are left in CLOSE_WAIT until the web server is rebooted.
--
Edit bug report at http://bugs.php.net/?id=27007&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=27007&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=27007&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=27007&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=27007&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=27007&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=27007&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=27007&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=27007&r=support
Expected behavior: http://bugs.php.net/fix.php?id=27007&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=27007&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=27007&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=27007&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27007&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=27007&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=27007&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=27007&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27007&r=float