This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 1c90ee4  Workaround JVM bug described in BZ 65710
1c90ee4 is described below

commit 1c90ee433ab6cda9f51fd1840e45c4e50e96afc1
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Dec 2 08:27:31 2021 +0000

    Workaround JVM bug described in BZ 65710
    
    In Java 8 (but not Java 11)
    Files.newInputStream(dfos.getFile().toPath()) leaks a file descriptor
    even after GC if the input stream is not explicitly closed.
    
    https://bz.apache.org/bugzilla/show_bug.cgi?id=65710
---
 java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java | 4 +++-
 webapps/docs/changelog.xml                                         | 6 ++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java 
b/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java
index 4dcc3d9..521abaf 100644
--- a/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java
+++ b/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java
@@ -193,7 +193,9 @@ public class DiskFileItem
     public InputStream getInputStream()
         throws IOException {
         if (!isInMemory()) {
-            return Files.newInputStream(dfos.getFile().toPath());
+            // Uses old code to avoid JVM bug
+            // https://bz.apache.org/bugzilla/show_bug.cgi?id=65710
+            return new FileInputStream(dfos.getFile());
         }
 
         if (cachedContent == null) {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index bbc985a..75d1215 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -132,6 +132,12 @@
         Add debug logging to the <code>RestCsrfPreventionFilter</code>. Based 
on
         pull request <pr>452</pr> by Polina Georgieva. (markt)
       </add>
+      <add>
+        <bug>65710</bug>: Implement a workaround for a JVM bug that can trigger
+        a file descriptor leak when using multi-part upload and the application
+        does not explicitly close an input stream for an uploaded file that was
+        cached on disk. (markt)
+      </add>
     </changelog>
   </subsection>
   <subsection name="Coyote">

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to