Bug #8467 DNS failure in reverse lookup cached as negative response
Submitted: 12 Feb 2005 2:40 Modified: 12 May 2005 14:56
Reporter: Jeremy Cole (Basic Quality Contributor) (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:all OS:Any (all)
Assigned to: Michael Widenius CPU Architecture:Any

[12 Feb 2005 2:40] Jeremy Cole
Description:
If a DNS server is unavailable, when the client connects, the failure return from ip_to_hostname() is cached as a negative response (e.g. no hostname associated with IP).  DNS failures should not be cached, otherwise transient DNS failure may leave any number of clients (those that attempted to connect during the outage) unable to connect indefinitely.

How to repeat:
Kill DNS server.
Attempt connection. (denied)
Start DNS server.
Attempt connection. (still denied! -- should be allowed)

Suggested fix:
===== sql/hostname.cc 1.20 vs edited =====
--- 1.20/sql/hostname.cc        2003-01-27 22:38:22 -08:00
+++ edited/sql/hostname.cc      2005-02-11 17:50:41 -08:00
@@ -175,7 +175,8 @@
                                 &tmp_errno)))
   {
     DBUG_PRINT("error",("gethostbyname_r returned %d",tmp_errno));
-    add_wrong_ip(in);
+    if(tmp_errno == HOST_NOT_FOUND || tmp_errno == NO_DATA) 
+      add_wrong_ip(in); /* only cache negative responses, not failures */
     my_gethostbyname_r_free();
     DBUG_RETURN(0);
   }
[25 Feb 2005 21:46] Timothy Smith
Hi, Jeremy.

Thanks for the excellent bug report.

I verified this on Windows XP, but the caching is OS-independent.

Timothy
[5 Mar 2005 0:06] Jeremy Cole
Same patch as added to the support ticket.

Attachment: dns_cache_bug_new.patch (application/octet-stream, text), 1.45 KiB.

[29 Apr 2005 10:47] Michael Widenius
I have added the proposed patch for now to the 4.1 tree as it should be better than what we have now.

I leave the bug state as 'need feedback' to make it clear that we are still waiting for more feedback from Jeremy.
[29 Apr 2005 10:48] Michael Widenius
I have added the proposed patch for now to the 4.1 tree as it should be better than what we have now.

I leave the bug state as 'need feedback' to make it clear that we are still waiting for more feedback from Jeremy.
[2 May 2005 22:33] Jeremy Cole
Hi Monty,

Have you added the patch in this bug, or the one in the support ticket?  The one in the support ticket fixes another case that this one doesn't catch.

Regards,

Jeremy
[6 May 2005 10:28] Jani Tolonen
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html
[10 May 2005 9:48] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/24767
[10 May 2005 21:38] Jeremy Cole
My question wasn't answered, but the bug was closed...
[12 May 2005 14:56] Sergei Golubchik
Jeremy, check the patch that is referenced from the ticket (a link to internals) - it is supposed to fix the problem. (actually 4.1.12 is being built now, so you may want to decide to wait for it)