[ 
https://issues.apache.org/jira/browse/FILEUPLOAD-368?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18074183#comment-18074183
 ] 

Bruno Antunes commented on FILEUPLOAD-368:
------------------------------------------

As a final observation:
 * Closing the {{InputStream}} returned by {{FileItem.getInputStream()}} should 
be the responsibility of the calling application; this aligns with general Java 
best practices for stream handling.
 * In this context, explicitly closing streams avoids reliance on 
GC/finalization for resource cleanup.

The behavior difference observed between versions appears related to the change 
in implementation from {{FileInputStream}} to {{Files.newInputStream(Path)}} 
(i.e. {{java.io}} vs {{{}java.nio{}}}). This may affect how unclosed streams 
are eventually cleaned up by the JVM.

It may be worth reviewing the Javadoc for {{DiskFileItem.getInputStream()}} to 
make the expectation to explicitly close the returned stream more explicit, 
possibly aligning with guidance in newer JDK documentation (e.g. 
{{{}java.nio.file.Files{}}}).

Also, since finalization has been deprecated for removal in more recent Java 
versions, relying on it for resource cleanup is increasingly discouraged.

> 1.6.0 unlike 1.5:  brought on an issue where temporary files and descriptors 
> were not being freed
> -------------------------------------------------------------------------------------------------
>
>                 Key: FILEUPLOAD-368
>                 URL: https://issues.apache.org/jira/browse/FILEUPLOAD-368
>             Project: Commons FileUpload
>          Issue Type: Bug
>    Affects Versions: 1.6.0
>            Reporter: David Campbell
>            Priority: Major
>         Attachments: fileupload-repro-src.zip, 
> image-2025-12-02-13-22-04-101.png, image-2025-12-02-13-24-56-498.png
>
>
> An upgrade of commons-fileupload from 1.5 to 1.6.0 brought on a problem on 
> high-load servers where uploaded files were not being deleted and the server 
> file descriptor utilisation kept growing.  On all server instances, file 
> resource utilisation kept growing to the point where it was filling /tmp 
> completely and then the server instances needed restarting to solve, as file 
> space is not reclaimed even on file deletion on Unix servers when file 
> descriptors are still open.  The same issue occurred on all our server 
> instances.
> We had a major production incident as a result.
> Rolled back to 1.5.  That fixed the issue, problem completely gone.
> Don't know any further details of the whys at this point.
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to