This repository has been archived by the owner on Apr 18, 2023. It is now read-only.
Fix response already committed error/corruption of response #26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes Unidata/thredds#1052 and other associated issues.
When serving a GetMap request and the client connection is closed prior to completing the response, javax.imageio.stream.MemoryCacheImageInputStream was not being closed properly due to a ClientAbortException being thrown when trying write to and then flush/close the stream (at https://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/9d617cfd6717/src/share/classes/javax/imageio/ImageIO.java#l1580). This class has a finalizer inherited from one of its parent classes (https://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/9d617cfd6717/src/share/classes/javax/imageio/stream/ImageInputStreamImpl.java#l871) which closes the stream if its still open. Finalizers are invoked some time later by the finalizer thread (essentially a random time later). Closing MemoryCacheImageInputStream closes its wrapped output stream (in this case the ServletOutputStream). Tomcat reuses ServletOutputStream instances and so this output stream may be being used by another request and being flushed/closed inappropriately during that processing.
This is a known issue with these core java classes and tomcat (refer https://mail-archives.apache.org/mod_mbox/tomcat-users/201306.mbox/%[email protected]%3E and https://bugs.java.com/view_bug.do?bug_id=6299405) with the recommended solution included below.
We have been using this code in our production thredds instance now for almost 2 years with no issues and no "Yikes! Response is already committed (Heiko's bug?)" messages in the log.