HTML to PDF / DOCX / RTF Java converter library Forums PD4ML v3 Archived Forums (Read Only) Troubleshooting SocketException: Socket closed on PD4Device.finalize

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #26514

    Hi Gurus, we use PD4ML within a Servlet to generate PDF from JSPs. Intermittent we get the exception you can see below.
    The code we use to generate the output is as follows:

    ServletOutputStream os = res.getOutputStream();<br /> pd4ml.render(new URL(urlString), os);<br /> os.flush();<br /> os.close();<br />
    Does anybody have an idea what the reason for this error?
    Greetings from Lutz

    WARNUNG: Unable to send headers<br /> java.net.SocketException: Socket closed<br /> at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:99)<br /> at java.net.SocketOutputStream.write(SocketOutputStream.java:136)<br /> at org.apache.jk.common.ChannelSocket.send(ChannelSocket.java:531)<br /> at org.apache.jk.common.JkInputStream.appendHead(JkInputStream.java:313)<br /> at org.apache.jk.core.MsgContext.action(MsgContext.java:266)<br /> at org.apache.coyote.Response.action(Response.java:183)<br /> at org.apache.coyote.Response.sendHeaders(Response.java:379)<br /> at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:305)<br /> at org.apache.catalina.connector.OutputBuffer.close(OutputBuffer.java:273)<br /> at org.apache.catalina.connector.CoyoteOutputStream.close(CoyoteOutputStream.java:104)<br /> at org.zefer.pd4ml.pdf.PD4Device.dispose(Unknown Source)<br /> at org.zefer.pd4ml.pdf.PD4Device.finalize(Unknown Source)<br /> at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)<br /> at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)<br /> at java.lang.ref.Finalizer.access$100(Finalizer.java:14)<br /> at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)

    #28384

    Some analysis shoes, that the class PD4ML calls the PD4Device method “dispose()” after completing the current rendering.
    This method will close the the output stream member within the PD4Device instance, but does not set it to null.
    The PD4Device class has a finalize method too. Now, the gc is collecting and calls the finalize method and tries to close the output stream again.
    Maybe that´s the problem causing the the raised exception.
    How can we get rid of this?
    Any idea?

    @Lutz.Strobel wrote:

    Hi Gurus, we use PD4ML within a Servlet to generate PDF from JSPs. Intermittent we get the exception you can see below.
    The code we use to generate the output is as follows:

    ServletOutputStream os = res.getOutputStream();<br /> pd4ml.render(new URL(urlString), os);<br /> os.flush();<br /> os.close();<br />
    Does anybody have an idea what the reason for this error?
    Greetings from Lutz

    WARNUNG: Unable to send headers<br /> java.net.SocketException: Socket closed<br /> at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:99)<br /> at java.net.SocketOutputStream.write(SocketOutputStream.java:136)<br /> at org.apache.jk.common.ChannelSocket.send(ChannelSocket.java:531)<br /> at org.apache.jk.common.JkInputStream.appendHead(JkInputStream.java:313)<br /> at org.apache.jk.core.MsgContext.action(MsgContext.java:266)<br /> at org.apache.coyote.Response.action(Response.java:183)<br /> at org.apache.coyote.Response.sendHeaders(Response.java:379)<br /> at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:305)<br /> at org.apache.catalina.connector.OutputBuffer.close(OutputBuffer.java:273)<br /> at org.apache.catalina.connector.CoyoteOutputStream.close(CoyoteOutputStream.java:104)<br /> at org.zefer.pd4ml.pdf.PD4Device.dispose(Unknown Source)<br /> at org.zefer.pd4ml.pdf.PD4Device.finalize(Unknown Source)<br /> at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)<br /> at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)<br /> at java.lang.ref.Finalizer.access$100(Finalizer.java:14)<br /> at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)

    #28385

    Yes, you are right: there is a possibility PD4ML tries to close output stream twice, however we never faced with such kind of exceptions in our test scenarios.

    We’ve just implemented a fix in the development build.

    On the other hand we would recommend to use ByteArrayOutputStream as a receiver for generated PDF bytes and to send the buffer content to ServletOutputStream at once.

Viewing 3 posts - 1 through 3 (of 3 total)

The forum ‘Troubleshooting’ is closed to new topics and replies.