-
Bug
-
Resolution: Fixed
-
P4
-
1.4.2_12, 5.0
-
b03
-
x86
-
linux, solaris_10
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2155961 | 6u10 | Chris Hegarty | P3 | Resolved | Fixed | b25 |
JDK-2168687 | 5.0u17 | Abhijit Saha | P3 | Resolved | Fixed | b02 |
JDK-2155960 | 5.0u16-rev | Abhijit Saha | P3 | Resolved | Fixed | b07 |
JDK-2168770 | 1.4.2_19 | Abhijit Saha | P3 | Resolved | Fixed | b01 |
JDK-2155959 | 1.4.2_18-rev | Abhijit Saha | P3 | Resolved | Fixed | b08 |
FULL PRODUCT VERSION :
1.5.0_06 as well as 1.4.2
A DESCRIPTION OF THE PROBLEM :
An input stream from a URLConnection reading a HTTP 1.1 chunked response body reads data into memory when #available() is called. If the client of the URLConnection object calls #available() repeatedly while reading only little data the whole response ends up in memory.
This case occurs in real life if you use a combination of BufferedInputStream, InputStreamReader and BufferedReader to read the response stream line by line as the second testcase demonstrates. It is important to use a buffer size larger than the default with the BufferedInputStream.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Replace the URL in the testcase with a URL known to point to a large file and known to produce a chunked response. A good way to do this is a servlet that does not set the content length header and simple writes a lot of data.
Run the test case.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The file should be downloaded with minimum heap requirements.
ACTUAL -
You can see the heap increasing, more and more full GCs until you hit OutOfMemory.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.*;
import java.net.URL;
public class HttpUrlConnectionRunsOutOfMemory {
public static void main(String[] args) throws IOException {
InputStream inputStream = new URL("http://localhost:8001/demo/servlet/reportlog?mode=get&name=1151054069229").openStream(); // replace this URL
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, 8192); // default buf size will not trigger the bug
InputStreamReader inputStreamReader = new InputStreamReader(bufferedInputStream);
BufferedReader reader = new BufferedReader(inputStreamReader);
while (reader.readLine() != null);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use a smaller buf size with the buffered input stream.
1.5.0_06 as well as 1.4.2
A DESCRIPTION OF THE PROBLEM :
An input stream from a URLConnection reading a HTTP 1.1 chunked response body reads data into memory when #available() is called. If the client of the URLConnection object calls #available() repeatedly while reading only little data the whole response ends up in memory.
This case occurs in real life if you use a combination of BufferedInputStream, InputStreamReader and BufferedReader to read the response stream line by line as the second testcase demonstrates. It is important to use a buffer size larger than the default with the BufferedInputStream.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Replace the URL in the testcase with a URL known to point to a large file and known to produce a chunked response. A good way to do this is a servlet that does not set the content length header and simple writes a lot of data.
Run the test case.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The file should be downloaded with minimum heap requirements.
ACTUAL -
You can see the heap increasing, more and more full GCs until you hit OutOfMemory.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.*;
import java.net.URL;
public class HttpUrlConnectionRunsOutOfMemory {
public static void main(String[] args) throws IOException {
InputStream inputStream = new URL("http://localhost:8001/demo/servlet/reportlog?mode=get&name=1151054069229").openStream(); // replace this URL
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, 8192); // default buf size will not trigger the bug
InputStreamReader inputStreamReader = new InputStreamReader(bufferedInputStream);
BufferedReader reader = new BufferedReader(inputStreamReader);
while (reader.readLine() != null);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use a smaller buf size with the buffered input stream.
- backported by
-
JDK-2155959 HttpURLConnection#available() reads more and more data into memory
- Resolved
-
JDK-2155960 HttpURLConnection#available() reads more and more data into memory
- Resolved
-
JDK-2155961 HttpURLConnection#available() reads more and more data into memory
- Resolved
-
JDK-2168687 HttpURLConnection#available() reads more and more data into memory
- Resolved
-
JDK-2168770 HttpURLConnection#available() reads more and more data into memory
- Resolved
- duplicates
-
JDK-6606430 OOME caused by ChunkedInputStream implementation change in 1.4.2
- Closed
(1 duplicates)