Howdy,
This is sort of continuation from
this thread. In my application I have a Spring controller which serves files to requests. In that controller if there is any exception I send the user to an error page (using ModelAndView of Spring). Now while writing the response
JSP page, the response "hangs" at Deflater.deflateBytes method.
Edit: There is a filter applied to each request to Zip/compress the response. The Deflater.deflateBytes is called when the filter tries to compress the response. It works fine everywhere except here.
This is what my code looks like
As far as I could figure out, whenever there is an exception (which most probably is "Connection reset by peer: socket write error"), when I return an error page to the response, the
thread hangs at
It starts taking a lot of CPU time. When I searched on the internet, other people also seem to have this problem (with no solution):
http://www.java.net/forum/topic/glassfish/glassfish/glassfish-301-gzip-problem-threads-apparently-spinning-100-cpu-use
http://stackoverflow.com/questions/6584765/thread-locking-when-flushing-jsp-file
https://forums.oracle.com/forums/thread.jspa?messageID=4627097
The problem seems to be with thread safety i.e. two thread writing to the same output stream. My doubt is that while the code is streaming the file to user, if user cancels it/closes the browser window, then it throws some IOException and after that the code tries to write a JSP error page to the same stream (which is already closed) which causes it to go nuts.
Is there a way to avoid this problem or maybe make the deflateBytes timeout somehow (highly unlikely but still

)? This problem is not very easy to reproduce so its very hard to apply a fix for it
[Edit: Added some more information]