Bug #67231 use mysql_real_connect to be held with no return value
Submitted: 15 Oct 2012 9:10 Modified: 18 Dec 2012 2:33
Reporter: Jack Lee Email Updates:
Status: Verified Impact on me:
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:5.0.95, 5.1.67, 5.5.30, 5.7.0 OS:Linux
Assigned to: CPU Architecture:Any
Tags: mysql_real_connect connect timeout
Triage: Needs Triage: D3 (Medium)

[15 Oct 2012 9:10] Jack Lee
When i use mysql_real_connect to connect to a unaccessiable IP address, it won't return

How to repeat:
OS: SUSE Linux 3.0.13
MySQL: 5.0.95

The code for connect is below:

#include <mysql.h>

void main(){

MYSQL  *dbHandle = NULL;

char dbHost[] = "";   
/*  The Intranet segment is 172.17.xxx.xxx   */
char dbUser[] = "dbtest";
char dbPass[] = "123";
char dbName[] = "test";

dbHandle = mysql_init(NULL);
if (NULL == dbHandle){
   /*  error process  */

dbHandle = mysql_real_connect(dbHandle, , dbUser, dbPass, dbName, 0, NULL, 0);
if (NULL == dbHandle){
   /*  error process  */

/*   other process  */

Run the code above, it will stop at mysql_real_connect and hold there over 10 minutes.

But if you change the dbHost to "" which is in Intranet but unaccessible, then the program will only stop at mysql_real_connect for about 20 seconds

Suggested fix:
But on Windows XP and MySQL 5.5.28, no matter whether the ip is or, no matter the unaccessible ip address is in Intranet or not, the mysql_real_connect will return in 20 seconds with error information below:
error:   Can't connect to MySQL server on 'xx.xx.xx.xx' (10060)
errno:   2003

Is this problem related to MySQL version? Version 5.0.95 maybe too old and the problem has been fixed in later version?
[6 Dec 2012 19:27] Sveta Smirnova
Thank you for the report.

Verified as described:

[sveta@delly bugs]$ time ./bug67231

real	3m9.392s
user	0m0.001s
sys	0m0.003s

Setting option connect_timeout for client and MYSQL_OPT_CONNECT_TIMEOUT do not help.
[18 Dec 2012 2:33] Jack Lee
How is the bug now?   Is there any progress?