#27007 [Opn->Bgs]: Failed pg_connect leaves Network Socket in CLOSE_WAIT State
| From: | iliaa@php.net | Date: | Thu, 29 Jan 2004 02:28:40 +0000 |
| Subject: | #27007 [Opn->Bgs]: Failed pg_connect leaves Network Socket in CLOSE_WAIT State | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-54095@lists.php.net to get a copy of this message | ||
ID: 27007
Updated by: iliaa@php.net
Reported By: bty at requesttech dot com
-Status: Open
+Status: Bogus
Bug Type: PostgreSQL related
Operating System: RedHat 9
PHP Version: 4.3.4
New Comment:
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions.
Thank you for your interest in PHP.
The 'real' problem is in client libraries that actually
open & close sockets. PHP only calls the client library
that is the one to perform the various low level socket
operations. Assuming what you say is true, the bug lies
with the client library and not PHP.
Previous Comments:
------------------------------------------------------------------------
[2004-01-28 21:23:33] bty at requesttech dot com
The same behavior occurs in any situation where a FIN packet is
initiated by the server. MySQL, Oracle etc...
I do not need help using PHP I have been using since early V3 days and
have been a Linux developer for over 8 years now. The only problem is
PHP developers inability (laziness) to address real problems. Please
leave this bug report open until I have had a chance to fix the code
myself. You may want to recategorize as this is a more general flaw in
PHP as it shows up in other socket related functions.
------------------------------------------------------------------------
[2004-01-28 20:32:04] iliaa@php.net
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions.
Thank you for your interest in PHP.
PHP does not actually open the socket, this is done by the
PostgreSQL library functions PQconnectdb() or PQsetdb(). If
the socket is left in CLOSE_WAIT, then you either got a buy
PostgreSQL library or found a bug in PostgreSQL.
------------------------------------------------------------------------
[2004-01-28 08:35:19] bty at requesttech dot com
The code is only an example of what will cause the problem. The fact
that it is "insane" to do this does not eleminate the problem. Picture
hundreds of people failling to login to a high traffic web site. I
will have to HUP the server every couple of hours to fix PHPs problem.
Did you even bother to try the code? I have tcpdumps proving that PHP
is doing the WRONG thing.
------------------------------------------------------------------------
[2004-01-23 01:43:05] sniper@php.net
This is by design, actual closing of connections happens during request
shutdown. Doing such for loop is pretty insane anyway, don't you think?
:)
------------------------------------------------------------------------
[2004-01-22 12:16:20] bty at requesttech dot com
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 this bug report at http://bugs.php.net/?id=27007&edit=1