Bug 55842 - response.setBufferSize() does not seem to work properly
Summary: response.setBufferSize() does not seem to work properly
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 7.0.47
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
: 57138 (view as bug list)
Depends on:
Reported: 2013-12-04 15:56 UTC by Martin Maier-Moessner
Modified: 2014-10-24 20:15 UTC (History)
1 user (show)

Eclipse/Maven project to reproduce this bug (2.86 KB, application/octet-stream)
2013-12-05 15:16 UTC, Martin Maier-Moessner

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Maier-Moessner 2013-12-04 15:56:09 UTC
I found a problem with setting the buffer size for the ServletResponse. 
If I call 'response.setBufferSize(1,000,000);' and send about 20,000 characters, the response will be chunked even though it should not.
The response is sent in several chunks and contains the 'Transfer-Encoding: chunked' response header.
In my understanding in this case the response should be fully buffered on the server and then sent as a whole containing the Content-Length-header.

This causes a problem in my application because I want to use a larger buffer to be able to redirect to an error page if an error occurs during rendering the response. 

I was able to reproduce this on Tomcat 7.0.39, 7.0.40, 7.0.42, 7.0.47. Tomcat 7.0.37 works fine and as expected.

This is easily reproducable by using a JSP as follows:
for (int i = 0; i < 100; i++) {
	for (int j = 0; j < 100; j++) {
    response.getWriter().write("<br />");
Comment 1 Konstantin Kolinko 2013-12-04 21:02:55 UTC
1. Usually the buffer size of a JSP page is configured via @page directive.

I suspect that response.setBufferSize() is a wrong API here and configures something else.

2. What is the size of the first chunk of that chunked response?
Comment 2 Martin Maier-Moessner 2013-12-05 15:05:54 UTC
1. It is reproducable with a simple Servlet as well. In fact, I found this bug using a JSF application where the response was chunked, even though I set the context-param 'javax.faces.FACELETS_BUFFER_SIZE' to a high value (over 1MB). Myfaces calls response.setBufferSize with the correct value.

2. All chunks are 2,000 bytes (looks like this is some kind of default)

I have created and attached a simple project that you can use to see the problem. Just deploy the Servlet to Tomcat and run the test case. The test case shows the chunks in System.err.
Comment 3 Martin Maier-Moessner 2013-12-05 15:16:34 UTC
Created attachment 31095 [details]
Eclipse/Maven project to reproduce this bug

- Deploy the project on a Tomcat
- Run ChunkTest.testChunk() as Junit Test
- Look at System.err output
Comment 4 Mark Thomas 2013-12-06 12:26:52 UTC
Thanks for the report and test case. This has been fixed in 8.0.x and 7.0.x and will be included in 7.0.48 and 8.0.0-RC6 onwards.
Comment 5 Martin Maier-Moessner 2013-12-06 12:30:23 UTC
Thanks for the fast fix!
Comment 6 Mark Thomas 2014-10-24 20:15:05 UTC
*** Bug 57138 has been marked as a duplicate of this bug. ***