https://bz.apache.org/bugzilla/show_bug.cgi?id=59398

            Bug ID: 59398
           Summary: org.apache.catalina.connector.CoyoteWriter.close
                    throws org.apache.tomcat.jni.Error
           Product: Tomcat 8
           Version: 8.0.28
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: james.s...@metaswitch.com

(This is the first bug I've raised in Tomcat so apologies if I've missed
something out!)

In responding to a request in tomcat using a HttpServletResponse object,
xiResponse, our server create a JSON string to send back and writes it to the
response with the following code:

...
      writer = xiResponse.getWriter();
      writer.write(jsonToSend);
      writer.close();
...

Which throws the following exception:

org.apache.tomcat.jni.Error: 88: Socket operation on non-socket
at org.apache.tomcat.jni.Socket.sendbb(Native Method)
at
org.apache.coyote.http11.InternalAprOutputBuffer.writeToSocket(InternalAprOutputBuffer.java:287)
at
org.apache.coyote.http11.InternalAprOutputBuffer.writeToSocket(InternalAprOutputBuffer.java:265)
at
org.apache.coyote.http11.InternalAprOutputBuffer.flushBuffer(InternalAprOutputBuffer.java:213)
at
org.apache.coyote.http11.AbstractOutputBuffer.endRequest(AbstractOutputBuffer.java:378)
at
org.apache.coyote.http11.AbstractHttp11Processor.action(AbstractHttp11Processor.java:726)
at org.apache.coyote.Response.action(Response.java:177)
at org.apache.catalina.connector.OutputBuffer.close(OutputBuffer.java:306)
at org.apache.catalina.connector.CoyoteWriter.close(CoyoteWriter.java:108)
at dcl.mwp.servlet.EventProcessor.writeResponse(EventProcessor.java:684)
at dcl.mwp.servlet.EventProcessor.access$100(EventProcessor.java:53)
at
dcl.mwp.servlet.EventProcessor$AsyncListener.commandCompleted(EventProcessor.java:1129)
at
dcl.mwp.cstasoap.CSTASOAPCommandFactory$CSTASOAPAsyncCommand$CSTAAxis2Callback.onMessage(CSTASOAPCommandFactory.java:1754)
at
org.apache.axis2.description.OutInAxisOperationClient$NonBlockingInvocationWorker.run(OutInAxisOperation.java:471)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)

(Note that dcl.mwp.servlet.EventProcessor.writeResponse is the writer.close()
call above)

Catching this in a debugger shows that the writer.close() call failed as the
socket we're trying to close is '0' implying that something else has already
closed the socket. From this I think the exception thrown by sendbb is
perfectly valid but it shouldn't make it all the way up to the print writer.

>From the PrintWriter docs there should be no exception thrown by this method
and more over 'Closing a previously closed stream has no effect'.

Getting network capture from this event shows that the data we're trying to
send has been sent over the wire and the far end sent a 'fin' on the TCP
connection. Moving the writer.close() call above the writer.write() call
results in the same exception, indicating that the client is not responsible
for closing this under the feet of tomcat.

I believe something inside tomcat is recycling this socket under our feet but
even so I don't believe the writer.close call should fail in this way.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to