We use JAX-WS implementation with JAXB for webservices, we have recently upgraded to jdk 8, since then we are having an issue when our endpoint is sending the responses. After digging into it, I realized that the endpoint thread gets blocked when writing on the socket.
Here is thread stack trace from server side when the execution is blocked, as you can see it gets blocked when writing. The client side gets also blocked reading until reaches a timeout.
Daemon Thread [jaxws-engine-WSEndpointSever::WSEnpointServer-3-thread-1] (Suspended)
owns: Object (id=8288)
owns: Request$WriteStream (id=8289)
SocketDispatcher.write0(FileDescriptor, long, int) line: not available [native method] [local variables unavailable]
SocketDispatcher.write(FileDescriptor, long, int) line: 51
IOUtil.writeFromNativeBuffer(FileDescriptor, ByteBuffer, long, NativeDispatcher) line: 93
IOUtil.write(FileDescriptor, ByteBuffer, long, NativeDispatcher) line: 65
SocketChannelImpl.write(ByteBuffer) line: 470
Request$WriteStream.write(byte[], int, int) line: 391
ChunkedOutputStream.writeChunk() line: 125 [local variables unavailable]
ChunkedOutputStream.flush() line: 159 [local variables unavailable]
PlaceholderOutputStream.flush() line: 449 [local variables unavailable]
ServerConnectionImpl$1(FilterOutputStream).flush() line: 140 [local variables unavailable]
UTF8OutputStreamWriter.flush() line: 138
XMLStreamWriterImpl.flush() line: 397
XMLStreamWriterFactory$HasEncodingWriter(XMLStreamWriterFilter).flush() line: 56
SAAJMessage.writeTo(XMLStreamWriter) line: 365
MessageWrapper.writeTo(XMLStreamWriter) line: 206
StreamSOAP11Codec(StreamSOAPCodec).encode(Packet, OutputStream) line: 129
SOAPBindingCodec.encode(Packet, OutputStream) line: 227
ServerAdapter(HttpAdapter).encodePacket(Packet, WSHTTPConnection, Codec) line: 474
HttpAdapter.access$100(HttpAdapter, Packet, WSHTTPConnection, Codec) line: 90
HttpAdapter$HttpToolkit.handle(WSHTTPConnection) line: 716
ServerAdapter(HttpAdapter).handle(WSHTTPConnection) line: 260
WSHttpHandler.handleExchange(HttpExchange) line: 98
WSHttpHandler.access$000(WSHttpHandler, HttpExchange) line: 47
WSHttpHandler$HttpHandlerRunnable.run() line: 122
ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: 1142
ThreadPoolExecutor$Worker.run() line: 617
Thread.run() line: 745
This is happening in a random circumstances, when the responses are short it barely happens but it happens very frequently with large responses.
Is there anything new in java 8 that we should be aware?
Here is how it is basically published the webservice
Server side
Endpoint endpoint = Endpoint.create(inServiceImpl );
endpoint.setExecutor( m_threadPoolExecutor );
SOAPBinding binding = (SOAPBinding) endpoint.getBinding();
List<Handler> handlerChain = new LinkedList<Handler>();
handlerChain.add( new SOAPTraceHandler( jaxEndopoint.getEndPointURL(),jaxEndopoint.getService() ) );
binding.setHandlerChain( handlerChain );
// publish the endpoint and make available.
endpoint.publish( jaxEndopoint.getEndPointURL() );
Client side
m_service = proxy.getPort( Service.class );
BindingProvider binding = (BindingProvider) m_service;
Map<String, Object> ctxt = binding.getRequestContext();
ctxt.put(JAXWSProperties.REQUEST_TIMEOUT, 50000);
//run method.
m_service.runMethod(Payload);
Could it be related with the Chunked transfer enconding? I haven't found a way to disable chunked encoding for the response, is it possible to disable it?
I've also tried to use a jetty server as container using the WSServlet, then i go the following traces:
nov 10, 2014 4:20:14 EM com.sun.xml.ws.transport.http.servlet.WSServletDelegate doGet
SEVERE: caught throwable
javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.SAXException2: com.sun.istack.SAXException2: timeout
org.eclipse.jetty.io.EofException: timeout
javax.xml.transform.TransformerException: com.sun.istack.SAXException2: timeout
org.eclipse.jetty.io.EofException: timeout]
at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:322)
at com.sun.xml.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.java:142)
at com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:108)
at com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:258)
at com.sun.xml.ws.transport.http.HttpAdapter.encodePacket(HttpAdapter.java:320)
at com.sun.xml.ws.transport.http.HttpAdapter.access$100(HttpAdapter.java:93)
at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:454)
at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:129)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:160)
at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:75)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:755)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:366)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:982)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1043)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:865)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.xml.bind.MarshalException - with linked exception: [com.sun.istack.SAXException2: com.sun.istack.SAXException2: timeout org.eclipse.jetty.io.EofException: timeout javax.xml.transform.TransformerException: com.sun.istack.SAXException2: timeout org.eclipse.jetty.io.EofException: timeout]
Your help would be very appreciated. Thanks in advance.
Regards.