Description:
libmysqlclient returns not ETIMEDOUT but EINTR when timeout occurs.
Affected version : 4.0 - 5.5
How to repeat:
<conn.c>
int main() {
int timeout = 5;
MYSQL *mysql;
printf("connecting...\n");
mysql = mysql_init(NULL);
mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (const char *) &timeout);
if (mysql_real_connect(mysql, "<some unreachable address>",
"<...>", "<...>", "<...>", 3306, NULL, 0)) {
printf("success.\n");
mysql_close(mysql);
} else {
printf("error: %s\n", mysql_error(mysql));
}
}
<example>
$ ./conn
connecting...
error: Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (4)
$ perror 4
OS error code 4: Interrupted system call
Suggested fix:
I think libmysqlclient should return ETIMEDOUT instead of EINTR.
*** sql-common/client.c_org 2012-02-15 10:50:24.000000000 +0900
--- sql-common/client.c 2012-02-15 10:50:39.000000000 +0900
***************
*** 211,217 ****
if (!(res= poll(&ufds, 1, (int) timeout*1000)))
{
DBUG_PRINT("info", ("poll timed out"));
! errno= EINTR;
DBUG_RETURN(-1);
}
DBUG_PRINT("info",
--- 211,217 ----
if (!(res= poll(&ufds, 1, (int) timeout*1000)))
{
DBUG_PRINT("info", ("poll timed out"));
! errno= ETIMEDOUT;
DBUG_RETURN(-1);
}
DBUG_PRINT("info",
<example>
$ ./conn
connecting...
error: Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (110)
$ perror 110
OS error code 110: Connection timed out