JDK-7155051 : DNS provider may return incorrect results
  • Type: Bug
  • Component: core-libs
  • Sub-Component: javax.naming
  • Affected Version: 6u24
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2012-03-20
  • Updated: 2013-09-12
  • Resolved: 2012-05-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
JDK 6 JDK 7 JDK 8
6u34Fixed 7u6Fixed 8 b34Fixed
Description
FULL PRODUCT VERSION :
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Server VM (build 19.1-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
SunOS nms-cricket 5.10 Generic_141414-01 sun4u sparc SUNW,Sun-Fire-V210

A DESCRIPTION OF THE PROBLEM :
The DNS provider attempts to check the XID of the response to make sure the response received from the server matches the requested XID.  If the response's XID does not match, the DNS provider caches the response in case another thread needs it.  However, the response is cached with the incorrect XID.  Therefore, when the lookup code continues, the current request receives an incorrect response.

I have included a patch that will correct the problem.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a new JNDI context that uses the DNS provider.  Attempt to do a a ctxt.getAttributes() using this context.  If multiple threads are involved, the results from the lookup can be incorrect.  This has a tendency to occur more frequently if the com.sun.jndi.dns.timeout.initial value is particularly low.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The expected result is to get the correct answer from the DNS lookup.
ACTUAL -
The lookup result may contain the answer from another query occurring from another thread.

REPRODUCIBILITY :
This bug can be reproduced occasionally.

---------- BEGIN SOURCE ----------
This can be reproduced with the standard usage of JNDI DNS provider.  I will include the diff that will correct this in the Workaround section.


---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
--- j2se/src/share/classes/com/sun/jndi/dns/DnsClient.java.orig 2011-08-20 14:06:55.000000000 -0400
+++ j2se/src/share/classes/com/sun/jndi/dns/DnsClient.java      2011-08-20 14:07:13.000000000 -0400
@@ -560,8 +560,8 @@ public class DnsClient {
        // enqueue only the first response, responses for retries are ignored.
        //
         synchronized (queuesLock) {
-           if (reqs.contains(xid)) { // enqueue only the first response
-               resps.put(xid, pkt);
+           if (reqs.contains(hdr.xid)) { // enqueue only the first response
+               resps.put(hdr.xid, pkt);
            }
         }

Comments
EVALUATION Fix as suggestion in the description
2012-03-20