CXF does not remove temporary files and kept file handlers open
Environment
- Red Hat Enterprise Application Platform (EAP) 7.2
- CXF 3.2.5.redhat-00001
LoggingInInterceptoris enabled- message attachments size exceeds the
org.apache.cxf.io.CachedWriter.Threshold(64kb by default)
- CXF 3.2.5.redhat-00001
Issue
- When the message attachment exceeds 64kb, CXF writes it as a temporary file but never deletes it.
- When the is system running on Windows, temporary files are locked and cannot be deleted.
- When
LoggingInInterceptoris enabled and CXF receive a message with an attachment greater than 64k a file handlers leak takes place.
Resolution
Note: The following workaround is risky because it can easily lead to an OOM.
The workaround is to increase the size of the threshold that drives the write on the disk of the message attachment with a value greater than any expected attachment size, using the system property org.apache.cxf.io.CachedWriter.Threshold (byte expressed with an integer, default 65536).
The fix has been scheduled for EAP 7.3.3.GA.
Root Cause
The component LoggingInInterceptor uses a CacheWriter to cache message attachment greater than the threshold (64k by default) on disk, but it does not close it and keeps file handler open indefinitely.
Diagnostic Steps
- Check the CXF temporary file folder (
org.apache.cxf.io.CachedOutputStream.OutputDirectory, the Java temp dir by default) for at least one file with the prefixcosand suffixtmp. - A check with the command
lsof <cos tmp file>will prove that its file handler is held by the EAP process.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.