Issue Details (XML | Word | Printable)

Key: FILEUPLOAD-95
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Unassigned
Reporter: Forrest Girouard
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Commons FileUpload

native memory leak results in container crash

Created: 06/Mar/04 12:07 AM   Updated: 09/Mar/07 08:32 PM
Return to search
Component/s: None
Affects Version/s: 1.1 Final
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments:
  Size
Text File DefaultFileItem.diff.txt 2004-03-07 07:07 AM Forrest Girouard 1 kB
Text File DeferredFileOutputStream.diff.txt 2004-03-07 07:08 AM Forrest Girouard 0.4 kB
Java Archive File ServerFile.jar 2004-03-07 07:22 AM Forrest Girouard 8 kB
Environment:
Operating System: All
Platform: All

Bugzilla Id: 27477


 Description  « Hide
Struts File Upload uses DiskFileUpload which in turn uses DefaultFileItem whose getTempFile() method
calls File.deleteOnExit() which is known to leak memory in the native heap. With our web app running
in WebSphere on AIX it crashes (coredumps) within hours under a constant load. IBM is unable to fix
the problem as it is in the JVM code they license from Sun and they are not allowed to modify. This
means it exists in all JVMs. Please see http://
developer.java.sun.com/developer/bugParade/bugs/4513817.html

Noel Bergman is playing around with using PhantomReferences in order to avoid this problem.

Clearly File.deleteOnExit() must be avoided but I'm not sure that using the PhantomReferences isn't
going to have it's own problems. For example, won't temporary files be leaked with the JVM is stopped
and restarted?



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Forrest Girouard added a comment - 07/Mar/04 07:07 AM
Created an attachment (id=10689)
o.a.commons.fileupload.DefaultFileItm used by o.a.struts.upload package.

Forrest Girouard added a comment - 07/Mar/04 07:08 AM
Created an attachment (id=10690)
o.a.commons.fileupload.DeferredFileOutputStream used by o.a.struts.upload package.

Forrest Girouard added a comment - 07/Mar/04 07:22 AM
Created an attachment (id=10691)
Archive containing ServerFileItem.java, ServerFileItemFactory.java and ServerFileMultipartRequestHandler.java.

Forrest Girouard added a comment - 07/Mar/04 07:34 AM
I just attached to patch files. One for org.apache.commons.fileupload.DefaultFileItem.java and the
other for org.apache.commons.fileupload.DeferredFileOutputStream.java. The changes to
DefaultFileItem enable subclassing while the change to DeferredFileOutputStream fixes what appears to
be a bug according to the existing javadocs.

I also attached a Java archive containing three new classes: ServerFileItem, ServerFileItemFactory and
ServerFileMultipartRequestHandler. The first two classes simply sublcass DefaultFileItem and
DefaultFileItemFactory, respectively. They do this to remove the call to File.deleteOnExit() which should
never be called from a long running server (and hence the name ServerFile). The third class uses the
first two. I've stress tested all these changes and they appear to alleviate the massive memory leak in
the native heap caused by the File.deleteOnExit() method. The disadvantage is that file space will be
leaked instead but that can be pragmatically addressed through the use of a cron job or some such.

A better solution IMO is to make use a mechanism that "manages" temporary file space (FileManager).
For example, ManagedFileItem, ManagedFileItemFactory, and ManagedFileMultipartRequestHandler are
the names of classes that I've created to make use of such a file manager (internally developed and not
publicly available at this time). To get this working it was also necessary to create a
DeferredManagedFileOutputStream that takes a FileManager reference in the contructor and only calls
FileManager.createManagedFile(...) from within the thresholdReached() method.


Noel J. Bergman added a comment - 17/Mar/04 11:39 PM
      • COM-1192 has been marked as a duplicate of this bug. ***

Martin Cooper added a comment - 23/Mar/04 01:31 PM
      • *** Bug 27777 has been marked as a duplicate of this bug. *** has been marked as a duplicate of this bug. ***

Martin Cooper added a comment - 12/Oct/04 11:21 AM
Fixed in the 20041012 nightly build.

Instead of using File.deleteOnExit(), we now use the FileCleaner class from
Commons IO, which will delete the file when its associated FileItem is garbage
collected.


Niall Pemberton added a comment - 28/Sep/05 10:30 PM
      • COM-2432 has been marked as a duplicate of this bug. ***

Henri Yandell made changes - 16/May/06 09:38 AM
Field Original Value New Value
issue.field.bugzillaimportkey 27477 12341308
Henri Yandell made changes - 16/May/06 11:35 AM
Key COM-1156 FILEUPLOAD-95
Affects Version/s 1.1 Final [ 12311652 ]
Assignee Martin Cooper [ martinc ]
Component/s FileUpload [ 12311116 ]
Project Commons [ 12310458 ] Commons FileUpload [ 12310476 ]
Henri Yandell made changes - 16/May/06 12:28 PM
Affects Version/s 1.1 Final [ 12311751 ]
Henri Yandell made changes - 09/Mar/07 08:32 PM
Status Resolved [ 5 ] Closed [ 6 ]