Bug #76507 Useless inclusion of errno in CR_UNKNOWN_HOST message
Submitted: 27 Mar 2015 13:14 Modified: 9 Apr 2015 22:39
Reporter: Marcin Owsiany Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.5/5.6/5.7 OS:Linux (Ubuntu)
Assigned to: CPU Architecture:Any

[27 Mar 2015 13:14] Marcin Owsiany
Description:
sql-common/client.c CLI_MYSQL_REAL_CONNECT contains:

    gai_errno= getaddrinfo(host, port_buf, &hints, &res_lst);

    if (gai_errno != 0)
    {
      /* 
        For DBUG we are keeping the right message but for client we default to
        historical error message.
      */
      DBUG_PRINT("info",("IPV6 getaddrinfo error %d", gai_errno));
      set_mysql_extended_error(mysql, CR_UNKNOWN_HOST, unknown_sqlstate,
                               ER(CR_UNKNOWN_HOST), host, errno);

In the last call, usage of errno instead of gai_errno is useless. At least on my system errno is zero, even when getaddrinfo() returns non-zero.

How to repeat:
$ mysql -h something
ERROR 2005 (HY000): Unknown MySQL server host 'something' (0)
$ 

This make it impossible to determine whether resolving "something" was a temporary or permanent error, or something else entirely - Manual page getaddrinfo(3) lists eleven possible error codes!

Suggested fix:
An improvement would be simply using gai_errno in the last call.

An even better approach would be to use gai_strerror(gai_errno) somewhere there.
[9 Apr 2015 22:39] Miguel Solorzano
Thank you for the bug report.

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
c:\dbs>5.5\bin\mysql -h something
ERROR 2005 (HY000): Unknown MySQL server host 'something' (2)
c:\dbs>5.6\bin\mysql -h something
ERROR 2005 (HY000): Unknown MySQL server host 'something' (0)
c:\dbs>5.7\bin\mysql -h something
ERROR 2005 (HY000): Unknown MySQL server host 'something' (0)
c:\dbs>5.0\bin\mysql -h something
ERROR 2005 (HY000): Unknown MySQL server host 'something' (11001)
c:\dbs>5.1\bin\mysql -h something
ERROR 2005 (HY000): Unknown MySQL server host 'something' (11001)

[miguel@vbcentos65 dbs]$ cat /etc/redhat-release
CentOS release 6.6 (Final)
[miguel@vbcentos65 dbs]$ 5.5/bin/mysql -h something
ERROR 2005 (HY000): Unknown MySQL server host 'something' (0)
[miguel@vbcentos65 dbs]$ 5.6/bin/mysql -h something
ERROR 2005 (HY000): Unknown MySQL server host 'something' (0)
[miguel@vbcentos65 dbs]$ 5.7/bin/mysql -h something
ERROR 2005 (HY000): Unknown MySQL server host 'something' (0)
[miguel@vbcentos65 dbs]$