Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with GZIPResponseStream hanging at deflateBytes

 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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]
 
abani patra
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You have not mention the response header and content type , Please try to set it and test.
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have set the response content type (its not visible in this code). Anyway for now I've excluded this particular path from the GZip filter to solve this problem. Even though that's not a proper solution but it works for now...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic