You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Gary Potagal (JIRA)" <ji...@apache.org> on 2018/03/19 16:21:00 UTC

[jira] [Commented] (PDFBOX-4158) COSDocument and PDFMerger may not close all IO resources if closing of one fails

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

Gary Potagal commented on PDFBOX-4158:
--------------------------------------

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:

 
 * 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.
 * org.apache.pdfbox.cos.COSDocument#close()  if closing COSStream or COSObject results in IOException, close on scratchFile is never reached. 

As this is bringing down our production servers, I’ll try to add debugging and use try / catch / finally on every operation to see if the memory leak can be avoided and will submit a fix for your review

======

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)

 

> COSDocument and PDFMerger may not close all IO resources if closing of one fails
> --------------------------------------------------------------------------------
>
>                 Key: PDFBOX-4158
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4158
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 2.0.4, 2.0.9, 3.0.0 PDFBox
>            Reporter: Maruan Sahyoun
>            Priority: Minor
>
> As observed on the users mailing list  {{COSDocument.close}} and {{PDFMergerUtility.mergeDocuments}} might not close all IO resources if closing of one of the resources fails



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org