FULL PRODUCT VERSION :
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Server VM (build 16.3-b01, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [5.1.2600]
A DESCRIPTION OF THE PROBLEM :
When sending an HTTP stream with chunked transfer encoding, the final zero-length chunk is not always sent (observed via tcpdump). This has only been found to occur when sending the output stream from Windows, and has not been observed on Linux. Delays between writes to the OutputStream of the HttpURLConnection have been found to make the problem more likely. Flushing sometimes helps ensure the zero-length chunk is sent, but it does not entirely solve the problem.
If this is a problem with the socket being written to becoming invalid, then would expect an exception to be thrown. But no exceptions are thrown.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the test executable (may take more than one trial)
2. Use network analyzer tool (e.g. tcpdump) to check for zero-length chunk at the end of the chunked HTTP stream
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Zero-length chunk (0 CRLF or 30 0d 0a 0d 0a) at the end of the stream
ACTUAL -
No zero-length chunk. Only body of last chunk sent ( e.g. "XXXX...")
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
import java.io.*;
import java.net.*;
public class ChunkTester extends Thread {
public static void main(String[] args) throws Exception {
ChunkTester threadA = new ChunkTester();
threadA.start();
}
public void run() {
try {
URL url = new URL("http://localhost:80/chunkyserver");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setChunkedStreamingMode(2 * 1024);
DataOutputStream os = new DataOutputStream(conn.getOutputStream());
for (int j=0; j < 4; j++) {
String msg = "X";
for (int i = 0; i < 4 * 1024; i++) {
msg += "X";
}
os.writeBytes(msg);
Thread.sleep(1000); //milliseconds
}
os.close();
conn.disconnect();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Do not use chunked transfer encoding from a Windows client
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Server VM (build 16.3-b01, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [5.1.2600]
A DESCRIPTION OF THE PROBLEM :
When sending an HTTP stream with chunked transfer encoding, the final zero-length chunk is not always sent (observed via tcpdump). This has only been found to occur when sending the output stream from Windows, and has not been observed on Linux. Delays between writes to the OutputStream of the HttpURLConnection have been found to make the problem more likely. Flushing sometimes helps ensure the zero-length chunk is sent, but it does not entirely solve the problem.
If this is a problem with the socket being written to becoming invalid, then would expect an exception to be thrown. But no exceptions are thrown.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the test executable (may take more than one trial)
2. Use network analyzer tool (e.g. tcpdump) to check for zero-length chunk at the end of the chunked HTTP stream
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Zero-length chunk (0 CRLF or 30 0d 0a 0d 0a) at the end of the stream
ACTUAL -
No zero-length chunk. Only body of last chunk sent ( e.g. "XXXX...")
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
import java.io.*;
import java.net.*;
public class ChunkTester extends Thread {
public static void main(String[] args) throws Exception {
ChunkTester threadA = new ChunkTester();
threadA.start();
}
public void run() {
try {
URL url = new URL("http://localhost:80/chunkyserver");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setChunkedStreamingMode(2 * 1024);
DataOutputStream os = new DataOutputStream(conn.getOutputStream());
for (int j=0; j < 4; j++) {
String msg = "X";
for (int i = 0; i < 4 * 1024; i++) {
msg += "X";
}
os.writeBytes(msg);
Thread.sleep(1000); //milliseconds
}
os.close();
conn.disconnect();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Do not use chunked transfer encoding from a Windows client