Hi, 2017-06-02 23:44 GMT+03:00 Mark Thomas <ma...@apache.org>: > > On 02/06/2017 10:46, Violeta Georgieva wrote: > > 2017-06-02 12:37 GMT+03:00 Mark Thomas <ma...@apache.org>: > >> > >> On 02/06/2017 10:23, Violeta Georgieva wrote: > >>> Hi Mark, > >>> > >>> 2017-05-22 14:28 GMT+03:00 Mark Thomas <ma...@apache.org>: > >> > >> <snip/> > >> > >>>> I'm leaning towards thinking this is an application bug. > >>>> > >>>> If the application has two non-container threads, A and B, then, as per > >>>> section 2.3.3.4 of the Servlet spec, the application is responsible for > >>>> accessing the request from those threads in a thread-safe manner. > >>> > >>> Yep I agree with the above, but in this scenario we have one > > non-container > >>> thread A > >>> and the other thread B is actually a container thread that tries to > > send a > >>> notification for an error. > >>> > >>> org.apache.catalina.connector.CoyoteAdapter.asyncDispatch Exception > > while > >>> processing an asynchronous request > >>> java.lang.IllegalStateException: Calling [asyncError()] is not valid > > for a > >>> request with Async state [DISPATCHING] > >>> at org.apache.coyote.AsyncStateMachine.asyncError( > >>> AsyncStateMachine.java:398) > >>> at > > org.apache.coyote.AbstractProcessor.action(AbstractProcessor.java:393) > >>> at org.apache.coyote.Request.action(Request.java:390) > >>> at org.apache.catalina.core.AsyncContextImpl.setErrorState( > >>> AsyncContextImpl.java:385) > >>> at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch( > >>> CoyoteAdapter.java:175) > >>> at > > org.apache.coyote.AbstractProcessor.dispatch(AbstractProcessor.java:225) > >>> at org.apache.coyote.AbstractProcessorLight.process( > >>> AbstractProcessorLight.java:53) > >>> > >>> What do you think? > >> > >> I think I still need more clarity on what is going on. Going back to > >> your original e-mail, the problems start when: > >> > >> - At some point thread A makes dispatch() -> Async state is changed > >> to DISPATCHING > >> - At the same time a socket error occurs > > > > Client closes the connection while the application is writing the response. > > Sorry - still trying to clarify in my mind what is going on here. Is > this right? > > Application does async write (that does not complete). Container will > complete this later. > > Application calls dispatch. > > At the same time the application calls dispatch, the container tries to > complete the async write and that fails because the client disconnected? > > Error handling then fails because of the dispatch?
Try with this test https://github.com/violetagg/tomcat/commit/53564d4e73496cb3badcaaab81a1314cf2ed750d In order to be able to reproduce this threading issue, run it with a debugger and put break points on these two actions: https://github.com/apache/tomcat/blob/trunk/java/org/apache/coyote/AbstractProcessor.java#L382 https://github.com/apache/tomcat/blob/trunk/java/org/apache/coyote/AbstractProcessor.java#L392 When the debugger stops you will have two threads - one will be on ASYNC_DISPATCH the other on ASYNC_ERROR, choose first ASYNC_DISPATCH then you will be able to see something like: 05-Jun-2017 11:35:53.508 INFO [Thread-4] org.apache.coyote.AbstractProcessor.setErrorState An error occurred in processing while on a non-container thread. The connection will be closed immediately java.io.IOException: Broken pipe at sun.nio.ch.FileDispatcherImpl.write0(Native Method) at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47) at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93) at sun.nio.ch.IOUtil.write(IOUtil.java:65) at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471) at org.apache.tomcat.util.net.NioChannel.write(NioChannel.java:134) .... 05-Jun-2017 11:36:16.283 SEVERE [http-nio-127.0.0.1-auto-1-exec-3] org.apache.catalina.connector.CoyoteAdapter.asyncDispatch Exception while processing an asynchronous request java.lang.IllegalStateException: Calling [asyncError()] is not valid for a request with Async state [DISPATCHING] at org.apache.coyote.AsyncStateMachine.asyncError(AsyncStateMachine.java:398) at org.apache.coyote.AbstractProcessor.action(AbstractProcessor.java:393) at org.apache.coyote.Request.action(Request.java:405) at org.apache.catalina.core.AsyncContextImpl.setErrorState(AsyncContextImpl.java:386) at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:176) at org.apache.coyote.AbstractProcessor.dispatch(AbstractProcessor.java:225) Regards, Violeta > Mark > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org > For additional commands, e-mail: dev-h...@tomcat.apache.org >