Hello,

We tried using PDFBox 2.0.4 to merge PDF Documents, in order to allow the user 
Print all documents at once from the Browser.  The resulting document is sent 
to the print window.  In order to improve customer experience, documents are 
merged to the Servlet HTTP Output Stream.  It's possible for the user to close 
the window or network to time out, resulting in Exception below.

We used JProfiler to diagnose the memory leak and followed instructions: 
https://www.ej-technologies.com/resources/jprofiler/help/doc/#jprofiler.heapWalker.memoryLeaks

BiggestObject and Allocation Screen Captures are attached.   We also observed 
that Scratch File is not cleaned up.

In reviewing the code:


1.  
org.apache.pdfbox.multipdf.PDFMergerUtility#mergeDocuments(MemoryUsageSetting 
memUsageSetting)



finally{ } block loops over (PDDocument doc : tobeclosed) without catching 
Exception, probably causing the leak that we're seeing.



2.  org.apache.pdfbox.cos.COSDocument#close()





if closing COSStream or COSObject results in IOException, close on scratchFile 
is never reached.


I'll try to add debugging and use try / catch / finally on every operation to 
see if the memory leak can be avoided.  A couple of questions?


  1.  Is anyone else running into this and are there recommendations?
  2.  Any ETA on: https://issues.apache.org/jira/browse/PDFBOX-3999?  It's a 
little hard to follow, but it may make this fix a little easier.
  3.  If the fix works, can I open a pull request for someone to review?

Thank you in advance,


[cid:[email protected]]<http://navihealth.us/>


Gary Potagal
Principal Software Engineer
O: 1800.446.9614






===============

org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken 
pipe
        at 
org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:396)
        at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:426)
        at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:283)
        at 
org.apache.catalina.connector.OutputBuffer.writeByte(OutputBuffer.java:440)
        at 
org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:81)
        at 
org.apache.catalina.filters.ExpiresFilter$XServletOutputStream.write(ExpiresFilter.java:1016)
        at 
org.apache.pdfbox.pdfwriter.COSStandardOutputStream.write(COSStandardOutputStream.java:144)
        at org.apache.pdfbox.cos.COSName.writePDF(COSName.java:702)
        at 
org.apache.pdfbox.pdfwriter.COSWriter.visitFromName(COSWriter.java:1155)
        at org.apache.pdfbox.cos.COSName.accept(COSName.java:672)
        at 
org.apache.pdfbox.pdfwriter.COSWriter.visitFromDictionary(COSWriter.java:995)
        at org.apache.pdfbox.cos.COSDictionary.accept(COSDictionary.java:1325)
        at 
org.apache.pdfbox.pdfwriter.COSWriter.doWriteObject(COSWriter.java:522)
        at 
org.apache.pdfbox.pdfwriter.COSWriter.doWriteObjects(COSWriter.java:460)
        at org.apache.pdfbox.pdfwriter.COSWriter.doWriteBody(COSWriter.java:444)
        at 
org.apache.pdfbox.pdfwriter.COSWriter.visitFromDocument(COSWriter.java:1096)
        at org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:419)
        at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1367)
        at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1254)
        at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1232)
        at 
org.apache.pdfbox.multipdf.PDFMergerUtility.mergeDocuments(PDFMergerUtility.java:280)


This email, including attachments, may contain information that is privileged, 
confidential or is exempt from disclosure under applicable law (including, but 
not limited to, protected health information). It is not intended for 
transmission to, or receipt by, any unauthorized persons. If the reader of this 
message is not the intended recipient, or the employee or agent responsible for 
delivering the message to the intended recipient, you are hereby notified that 
any dissemination, distribution or copying of this communication is strictly 
prohibited. If you believe this email was sent to you in error, do not read it. 
Please notify the sender immediately informing them of the error and delete all 
copies and attachments of the message from your system. Thank you.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to