MySQL clients return bogus errno for host-not-found errors on Ubuntu 13.04
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MySQL Server |
Unknown
|
Unknown
|
|||
Percona Server moved to https://jira.percona.com/projects/PS |
Invalid
|
Undecided
|
Unassigned | ||
5.1 |
Fix Released
|
Medium
|
Laurynas Biveinis | ||
5.5 |
Invalid
|
Undecided
|
Unassigned | ||
5.6 |
Invalid
|
Undecided
|
Unassigned |
Bug Description
An upstream bug, which is a CI bug for us:
[2 Jun 8:00] Laurynas Biveinis
Description:
lp:mysql-server/5.1 revno 3997, compiled with BUILD/compile-
A quick analysis suggests that it's caused by a gethostbyname_r call that returns -1 (NETDB_INTERNAL) in the errno arg, which then means that the real errno should be read from the global errno var. If that's true, then still no idea why it's returning NETDB_INTERNAL in the first place.
How to repeat:
5.1$ bzr revno
3997
5.1$ BUILD/compile-
...
5.1$ cd mysql-test
5.1/mysql-test$ ./mysql-test-run --mem mysql
...
@@ -162,14 +162,14 @@
ERROR 1049 (42000) at line 1: Unknown database 'invalid'
Test connect with dbname + hostname
Test connect with dbname + _invalid_ hostname
-ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'invalid_hostname' (errno)
-ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'invalid_hostname' (errno)
+ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'invalid_hostname' (-1)
+ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'invalid_hostname' (-1)
The commands reported in the bug report
-ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyril has found a bug :)XXXXXXXXXXXXX
+ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyril has found a bug :)XXXXXXXXXXXXX
Too long dbname
ERROR 1102 (42000) at line 1: Incorrect database name 'test_really_
Too long hostname
-ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyrils_
+ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyrils_
1
1
ERROR at line 1: DELIMITER cannot contain a backslash character
@@ -198,7 +198,7 @@
1
COUNT (*)
1
-ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'invalid_hostname' (errno)
+ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'invalid_hostname' (-1)
End of 5.0 tests
WARNING: --server-arg option not supported in this configuration.
Warning (Code 1286): Unknown table engine 'nonexistent'
mysqltest: Result content mismatch
5.1/mysql-test$ ./mysql-test-run --mem mysql_upgrade
@@ -94,7 +94,7 @@
mysql.user OK
DROP USER mysqltest1@'%';
Run mysql_upgrade with a non existing server socket
-mysqlcheck: Got error: 2005: Unknown MySQL server host 'not_existing_host' (errno) when trying to connect
+mysqlcheck: Got error: 2005: Unknown MySQL server host 'not_existing_host' (-1) when trying to connect
FATAL ERROR: Upgrade failed
set GLOBAL sql_mode=
mtr.global_
Suggested fix:
Will be provided below if my analysis works out.
[2 Jun 8:54] Laurynas Biveinis
It appears that there are two issues.
1) gethostbyname_r returning -1 in h_errno, as described above
If this is fixed to copy errno to h_errno in my_gethostbynam
The commands reported in the bug report
-ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyril has found a bug :)XXXXXXXXXXXXX
+ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyril has found a bug :)XXXXXXXXXXXXX
Too long dbname
ERROR 1102 (42000) at line 1: Incorrect database name 'test_really_
Too long hostname
-ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyrils_
+ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyrils_
1
Thus,
2) this appears to be caused by gethostbyname_r returning 0 (success), but setting hostent *result to NULL.
[2 Jun 9:00] Laurynas Biveinis
The following fixes the testsuite failures for me. I have no idea whether that's really correct, as I was not find info under what circumstances gethostbyname_r returns such values. Also the *h_errno = errno copying makes the my_gethostbynam
This appears to be a 5.1-only issue BTW.
=== modified file 'mysys/my_net.c'
--- mysys/my_net.c 2013-03-19 12:29:12 +0000
+++ mysys/my_net.c 2013-06-02 08:56:24 +0000
@@ -60,9 +60,15 @@
int buflen, int *h_errnop)
{
struct hostent *hp;
+ int result_hostent;
DBUG_
- if (gethostbyname_
+ result_hostent= gethostbyname_
+ if (unlikely(
+ if (*h_errnop == NETDB_INTERNAL) {
+ *h_errnop= errno;
+ }
return 0;
+ }
return hp;
}
Related branches
- Stewart Smith (community): Approve
-
Diff: 19 lines (+7/-1)1 file modifiedPercona-Server/mysys/my_net.c (+7/-1)
tags: | added: ci upstream |
summary: |
- mysql and mysql_upgrade testcases fail on Ubuntu 13.04 (Raring Ringtail) + MySQL clients return bogus errno for host-not-found errors on Ubuntu + 13.04 |
Percona now uses JIRA for bug reports so this bug report is migrated to: https:/ /jira.percona. com/browse/ PS-2966