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

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


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

commit f4dab78c50567256aa234f9be13c407d58c73761
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 9610ae1..e9a1621 100644
--- a/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java
+++ b/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java
@@ -192,7 +192,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 6168046..821a316 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