https://issues.apache.org/bugzilla/show_bug.cgi?id=55438
Bug ID: 55438 Summary: Non Blocking API's onAllDataRead being called twice Product: Tomcat 8 Version: trunk Hardware: PC OS: Mac OS X 10.4 Status: NEW Severity: minor Priority: P2 Component: Catalina Assignee: dev@tomcat.apache.org Reporter: dmik...@gopivotal.com Created attachment 30738 --> https://issues.apache.org/bugzilla/attachment.cgi?id=30738&action=edit Patch against TestNonBlockingAPI.java I have a simple echo servlet which uses the Servlet 3.1 Non-Blocking IO API. It creates a ReadListener, that reads the request's input, buffers it, creates a WriteListener that takes the buffered input and echoes it back to the response. Most of the time this works OK, but when I send a request with no input data I get the following error. 6-Aug-2013 11:18:09.523 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 1452 ms java.lang.IllegalStateException: The non-blocking write listener has already been set at org.apache.coyote.Response.setWriteListener(Response.java:583) at org.apache.catalina.connector.OutputBuffer.setWriteListener(OutputBuffer.java:665) at org.apache.catalina.connector.CoyoteOutputStream.setWriteListener(CoyoteOutputStream.java:162) at com.pivotal.demos.nbio.EchoNbioServlet$1.onAllDataRead(EchoNbioServlet.java:77) at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:384) at org.apache.coyote.http11.AbstractHttp11Processor.asyncDispatch(AbstractHttp11Processor.java:1607) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:622) at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1592) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1550) 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:724) 16-Aug-2013 11:20:13.205 SEVERE [http-nio-8080-exec-7] org.apache.catalina.connector.CoyoteAdapter.asyncDispatch Exception while processing an asynchronous request java.lang.NullPointerException at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:429) at org.apache.coyote.http11.AbstractHttp11Processor.asyncDispatch(AbstractHttp11Processor.java:1607) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:622) at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1592) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1550) 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:724) Looking into it, what appears to be happening is that the "ReadListener.onAllDataRead()" method is being called twice. Because I'm setting the WriteListener in the "onAllDataRead" method, the second invocation of "onAllDataRead" causes the IllegalStateException. I was assuming that "onAllDataRead" should only be called once and so it would be OK to set the WriteListener in that method. Can "onAllDataRead" be legitimately called multiple times? Mark> No. Any chance you could convert the code below into a Tomcat unit test? Attaching unit test to replicate the issue. -- 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