JDK-7095949 : java/net/URLConnection/RedirectLimit.java and Redirect307Test fail intermittently
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7u1
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_2003
  • CPU: x86
  • Submitted: 2011-09-28
  • Updated: 2012-06-18
  • Resolved: 2012-06-18
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 Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7 JDK 8
6u32Fixed 7u4Fixed 8 b10Fixed
Description
see comments

Comments
EVALUATION JDK8 Changeset: Changeset: 24741fe639a8 Author: chegar Date: 2011-10-04 16:37 +0100 URL: http://hg.openjdk.java.net/jdk8/tl/jdk/rev/24741fe639a8 7095949: java/net/URLConnection/RedirectLimit.java and Redirect307Test fail intermittently Reviewed-by: alanb ! test/java/net/URLConnection/Redirect307Test.java ! test/java/net/URLConnection/RedirectLimit.java
04-10-2011

SUGGESTED FIX diff -r 8d88e694441c test/java/net/URLConnection/RedirectLimit.java --- a/test/java/net/URLConnection/RedirectLimit.java +++ b/test/java/net/URLConnection/RedirectLimit.java @@ -62,24 +62,37 @@ class RedirLimitServer extends Thread { port = ss.getLocalPort(); } + static final byte[] requestEnd = new byte[] {'\r', '\n', '\r', '\n' }; + + void readCompleteRequest(InputStream is) throws IOException { + int requestEndCount = 0, r; + while ((r = is.read()) != -1) { + if (r == requestEnd[requestEndCount]) { + requestEndCount++; + if (requestEndCount == 4) { + break; + } + } else { + requestEndCount = 0; + } + } + } + public void run() { try { ss.setSoTimeout(TIMEOUT); for (int i=0; i<NUM_REDIRECTS; i++) { try (Socket s = ss.accept()) { s.setSoTimeout(TIMEOUT); - InputStream is = s.getInputStream(); - OutputStream os = s.getOutputStream(); - is.read(); + readCompleteRequest(s.getInputStream()); String reply = reply1 + port + "/redirect" + i + reply2; - os.write(reply.getBytes()); + s.getOutputStream().write(reply.getBytes()); } } try (Socket s = ss.accept()) { - InputStream is = s.getInputStream(); - OutputStream os = s.getOutputStream(); - is.read(); - os.write(reply3.getBytes()); + s.setSoTimeout(TIMEOUT); + readCompleteRequest(s.getInputStream()); + s.getOutputStream().write(reply3.getBytes()); } } catch (Exception e) { e.printStackTrace(); Similar changes for Redirect307Test.java
04-10-2011

EVALUATION This is an issue with the testcase itself. The server side of the test only reads one byte of the HTTP request and then proceeds to send its response. For the testcase purposes it doesn't need to know the full request since the response is canned anyway. Then the socket on the server side is closed and the loop continues awaiting another connection. If the server closes the socket before the client has read the response the server will send a TCP RST (reset the connection) since there is unread data in the socket's receive buffer. This will cause the client side to fail. The solution is for the server to read the full HTTP request. This will avoid the above situation.
04-10-2011