[#3291] - File descriptor leak in JRSwapFile

Category:
Patch
Priority:
Normal
Status:
New
Project: Severity:
Minor
Resolution:
Open
Component: Reproducibility:
Sometimes
Assigned to:
1

The class net.sf.jasperreports.engine.util.JRSwapFile can leak a file descriptor. Over time, this can cause other parts of the program to fail in Unix with "Too many open files."

The JRSwapFile constructor unconditionally initializes the instance member "file" with a new RandomAccessFile, but dispose() closes it only conditionally. The attached patch updates dispose() to unconditionally close it.

AttachmentSize
File jrswapfile.java.patch849 bytes
v5.5.0
jack_s_tan's picture
Joined: Nov 21 2013 - 8:22pm
Last seen: 7 years 9 months ago

3 Comments:

#1
  • Assigned:nobody»

Unconditionally closing the RandomAccessFile seems logical, but I'm trying to understand the scenario in which swapFile.exists() is false in dispose(). Do you have any details on how that happens?

Regards,
Lucian

#2
  • Assigned:» anonymous

I haven't been able to find a reasonable explanation as to why swapFile.exists() is false in dispose(). I suppose an external process could periodically delete the files in the swap file directory to clean up orphaned files from crashed JVMs (e.g., Java out of memory), but that is atypical and speculative.

Nevertheless, a previous examination of the JVM showed hundreds of accumulating swap files. After making this change, we stopped getting "Too many open files" errors, and the JVM no longer needs to be restarted periodically.

#3
  • Assigned:anonymous» lucianc
Feedback