Edit report at http://bugs.php.net/bug.php?id=52948&edit=1

 ID:                 52948
 User updated by:    gilles dot rayrat at continuent dot com
 Reported by:        gilles dot rayrat at continuent dot com
 Summary:            Improper connection closing logic leads to TIME_WAIT
                     sockets on server
-Status:             Feedback
+Status:             Open
 Type:               Bug
 Package:            MySQLi related
 Operating System:   Any
 PHP Version:        5.2.14
 Block user comment: N

 New Comment:

Thanks for your answer.



Yes, the webserver should get the time_wait connections, since you can
have several web servers but generally only one database server

Furthermore, other mysql client (perl, CLI) will properly let the
time_wait connection on the client side



After some more testing, it actually appears that the behavior is
somehow unpredictable (or I didn't get the logic). I sometimes got
time_wait on the client, sometimes 

on the server - the following shows the case where it appears on the
server.



These tests are comparing regular mysql CLI client with a simple php
script.

Host u1 is the client (or webapp)

Host u2 is the mysql server



Mysql command line is:

mysql -hu2 -utungsten -psecret -P3306 test



Php script is:

<?php 

# Simple script to demonstrate the TIME_WAIT issue

# Connects to the database, nothing more



$host = "u2";         # Host where the Tungsten Connector is running

$port = 3306;            # Using the Tungsten Connector port 

$username = "tungsten"; 

$password = "secret"; 

$dbname = "test"; 

echo "Connecting to $host $username $password $dbname $port\n";

# Make the connection 

$connection = mysqli_connect($host, $username, $password, $dbname,
$port); 

$connection->close();

?> 



Command to check for time_wait:

netstat -nat| grep 3306| grep TIME_WAIT



Will attach both dumps taken with wireshark


Previous Comments:
------------------------------------------------------------------------
[2010-09-30 05:14:41] cataphr...@php.net

I'm sorry, I didn't get this. If I understand correctly, you would
prefer the web server to be in a TIME_WAIT, rather than the database
server, and for that it would have to send the first FIN packet.



But why would you prefer the web server to be in a TIME_WAIT state? The
front-end side typically needs to handle many more connections.



Additionally, it would be nice if you provided an example script and its
ouput (in this case, a tcpdump).

------------------------------------------------------------------------
[2010-09-29 08:36:08] gilles dot rayrat at continuent dot com

Description:
------------
Similarly to connector/j bug reported here:
http://bugs.mysql.com/bug.php?

id=56979, there is a problem with mysql disconnection logic where the
TCP 

connection TIME_WAIT state is found on the server rather than on the
client. With 

multiple clients and multiple connection, the MySQL server can run out
of file 

descriptors quickly.



The disconnect method should first set EOF to its input, then send the
QUIT 

command, then set its output to EOF, then close the socket



Note: I guess the same bug appears in MySQL-non-i as well



------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52948&edit=1

Reply via email to