goodier
goodier

Reputation: 395

tomcat does not send last chunk for chunked response

We're using tomcat 7.0.67 which is almost latest tomcat version of tomcat7. We found that after we ran some performance testing, the tomcat does not send chunked response correct. It does not send back "last chunk" which should be ZERO length. The problem continues when there is no requests on tomcat server. Does anyone ever see this? Is there a workaround for it?

Upvotes: 1

Views: 834

Answers (1)

goodier
goodier

Reputation: 395

I found the cause. We're using Async task. In foreground thread, we call ServletOutputStream.flush in some cases. In tomcat, ServletOutputStream.flush will cause tomcat to start computing the needed tomcat's OutputFilter. IdentityOutputFilter is used for non-chunk response. IdentityOutputFilter will be used if there is "connection:close" header or "content-length" set when flush. ChunkedOutputFilter is used for chunked response

But the background thread might be still processing and using ServletOutputStream. This premature flush will make tomcat chained IdentityOutputFilter and ChunkedOutputFilter in some cases. This might not be expected by tomcat and chunked response starts not working.

The workaround is not call flush in foreground thread, but I believe it is still a tomcat bug because tomcat chunked response should not stop working even webapp calls flush prematurely.

Upvotes: 2

Related Questions