MySQL clients return bogus errno for host-not-found errors on Ubuntu 13.04

Bug #1186690 reported by Laurynas Biveinis
6
This bug affects 1 person
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-amd64-debug-max-no-ndb fails mysql and mysql_upgrade testcases with what appears to be wrong errno value -1 in the client.

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-amd64-debug-max-no-ndb
...
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 :)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' (errno)
+ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyril has found a bug :)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' (-1)
 Too long dbname
 ERROR 1102 (42000) at line 1: Incorrect database name 'test_really_long_dbnamexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
 Too long hostname
-ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyrils_superlonghostnameXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' (errno)
+ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyrils_superlonghostnameXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' (-1)
 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='STRICT_ALL_TABLES,ANSI_QUOTES,NO_ZERO_DATE';
 mtr.global_suppressions OK

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_gethostbyname_r(), then the following testcase failure still remains:

 The commands reported in the bug report
-ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyril has found a bug :)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' (errno)
+ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyril has found a bug :)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' (-1)
 Too long dbname
 ERROR 1102 (42000) at line 1: Incorrect database name 'test_really_long_dbnamexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
 Too long hostname
-ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyrils_superlonghostnameXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' (errno)
+ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyrils_superlonghostnameXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' (-1)
 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_gethostbyname_r() interface deviate from the underlying gethostbyname_r() interface, which is also suboptimal I guess.

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_ASSERT((size_t) buflen >= sizeof(*result));
- if (gethostbyname_r(name,result, buffer, (size_t) buflen, &hp, h_errnop))
+ result_hostent= gethostbyname_r(name,result, buffer, (size_t) buflen, &hp, h_errnop);
+ if (unlikely(!result_hostent || !hp)) {
+ if (*h_errnop == NETDB_INTERNAL) {
+ *h_errnop= errno;
+ }
     return 0;
+ }
   return hp;
 }

Tags: ci upstream

Related branches

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
Revision history for this message
Shahriyar Rzayev (rzayev-sehriyar) wrote :

Percona now uses JIRA for bug reports so this bug report is migrated to: https://jira.percona.com/browse/PS-2966

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.