Bug #22434 mysql server in windows close connection
Submitted: 18 Sep 2006 9:18 Modified: 22 Oct 2006 7:22
Reporter: Jose Angel . Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.24a and 4.1.21 OS:Windows (Windows XP sp2)
Assigned to: CPU Architecture:Any

[18 Sep 2006 9:18] Jose Angel .
Description:
when I open many connections to mysql in windows server, reload page with this PHP code:

<?PHP
$num = 1000;
	
echo "numero: $num<br>";
for($i=0; $i < $num; $i++){
	$con = mysqli_connect("localhost","user","pass","bd1");
	$qry = "SELECT * FROM sys_usuarios WHERE uid = 2";
	$res = mysqli_query($con,$qry);
	if(!$res){
		die("Error: ".mysql_error());
	}
	$row = mysqli_fetch_array($res);
	echo "$i => ".$row['login']."<br>";
}
?>

Connection with Mysql close and show this error:
Can't connect to MySQL server on 'localhost' (10048)

Connection this in "TIME_WAIT" status, we can see it in console with "netstat" 
>TCP    host:3306           localhost:2883         TIME_WAIT

telnet localhost 3306 not work.

However this work fine in Linux server, 

Hardware (Windows XP Profesional Service pack 2):
  Intel Core duo T2500 2.0 GHz
  2GB RAM memory

Hardware (Linux Suse 9.3):
  2.40 GHz Intel Xeon.
  512MB RAM Memory
 

Excuse me for my bad english...

How to repeat:
In windows server, open many connection to mysql and execute simply query, if no crash try execute code 4 or 5 times quickly.

Example php code (if no crash reload page 4 or 5 times quickly):

<?PHP
$num = 1000;
	
echo "numero: $num<br>";
for($i=0; $i < $num; $i++){
	$con = mysqli_connect("localhost","user","pass","bd1");
	$qry = "SELECT * FROM sys_usuarios WHERE uid = 2";
	$res = mysqli_query($con,$qry);
	if(!$res){
		die("Error: ".mysqli_error($con));
	}
	$row = mysqli_fetch_array($res);
	echo "$i => ".$row['login']."<br>";
}
?>

The code connect to mysql 1000 times and execute simply query. I use mysqli driver, also crash with mysql driver.

<?PHP
     $con = mysql_connect("localhost","padron","indra",true);
     $db = mysql_select_db("ivtm",$con);
?>
[18 Sep 2006 10:56] Valeriy Kravchuk
Thank you for a problem report. Please, send/upload you my.ini file content and error log to this report.
[18 Sep 2006 12:18] Jose Angel .
not return error message in error log file .err

Attachment: diodeno.err (application/octet-stream, text), 260 bytes.

[18 Oct 2006 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[19 Oct 2006 8:01] Jose Angel .
how can I add feedback to bug?

I add my.ini and error log file 1 month ago.
[20 Oct 2006 11:32] Valeriy Kravchuk
Sorry, I missed them somehow.
[22 Oct 2006 2:44] Mark W
Any resultion on this issue? I am having the same problem. I did some further testing to help isolate the cause. I used the same method you provided to reproduce the problem. Below are some notes on my testing:

NO problem with exact same code and php/mysql implementation on Linux server.

php/mysql connection on windows server (using mysql_connect) works fine until you hit about 2000 connections inside of 20 seconds or so. The sql server seems to shut itself down (noted in error log as if it was a graceful shutdown) then brings itself back up shortly after.

ADDITIONAL TESTING

I tested the exact same query set on the same windows server with the same MYSQL database this time using ColdFusion as the middleware. Coldfusion worked without a problem using BOTH it's mysql driver AND connecting to the mysql DB via an ODBC connection.
[22 Oct 2006 3:03] Mark W
found this little ditty:

http://dev.mysql.com/doc/refman/5.1/en/can-not-connect-to-server-on-windows.html

I made the registry changes and......

it worked!!!!!!

I just beat the heck out of your script on like 8 browser windows simultaniously - no shut down!!!!!
[22 Oct 2006 7:23] Valeriy Kravchuk
Thank you for your persistence. So, you both were just running out of ports, it seems. As there is a documented workaround for that Windows-specific problem, I am closing this report as "Not a bug" (in MySQL code, at least) now.