Bug 51324 - When OutputBuffer.doFlush gets Exception, doFlush gets stuck to true
Summary: When OutputBuffer.doFlush gets Exception, doFlush gets stuck to true
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Connectors (show other bugs)
Version: 7.0.14
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-05 05:17 UTC by Bow Ruggeri
Modified: 2011-07-21 16:29 UTC (History)
0 users



Attachments
The line that causes doFlush to be stuck at true if it gets an exception (299 bytes, text/plain)
2011-06-05 05:17 UTC, Bow Ruggeri
Details
Patch (1.12 KB, patch)
2011-06-07 06:12 UTC, Jeremy Norris
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Bow Ruggeri 2011-06-05 05:17:12 UTC
Created attachment 27114 [details]
The line that causes doFlush to be stuck at true if it gets an exception

First time opening a bug, please forgive me if this report isn't perfect!

I recently ran into an issue where OutputBuffer's doFlush gets stuck to true.

In OutputBuffer.doFlush(boolean) it sets doFlush = true, then calls bb.flushBuffer, then sets doFlush = false.

I issue I ran into was bb.flushBuffer eventually calls OutputBuffer.realWriteBytes.  The realWriteBytes eventually calls coyoteResponse.doWrite.  If coyoteResponse.doWrite throws an IOException, then it rethrows a ClientAbortException.

What I am seeing is my client disconnecting early, and causing the doWrite to throw a SocketException of "Broken pipe".  That broken pipe causes a ClientAbortException to be thrown. 

When that is thrown, the error is bubbled up and doFlush is stuck as "true".  The next time the processor is used, it calls the recycle() method in OutputBuffer. However, the recycle doesn't reset doFlush so its still set to true.

I imagine there are quite a few ways to fix this, but the two obvious ones that come to mind are:

- Have recycle() set doFlush back to false

or 

- Have throw a finally in try/catch/finally in OutputBuffer.doFlush so doFlush is set back to false when an Exception is catch
Comment 1 Jeremy Norris 2011-06-07 06:12:53 UTC
Created attachment 27122 [details]
Patch
Comment 2 Jeremy Norris 2011-06-07 06:14:27 UTC
I'm also experiencing this problem.  Attached is a patch implementing both of Bow's suggestions.
Comment 3 Mark Thomas 2011-06-07 14:00:47 UTC
Thanks for the patch. This has been fixed in 7.0.x and will be included in 7.0.16 onwards.
Comment 4 Konstantin Kolinko 2011-07-05 08:59:07 UTC
Proposed for backport to 6.0 and 5.5.
Comment 5 Mark Thomas 2011-07-21 16:29:04 UTC
Fixed in 6.0.x and included in 6.0.33 onwards