Project: Tomcat
Bug 44646 IllegalStateException when using CometConnectionManagerValve
Reported: 2008-03-20 09:33:14 | Status: resolved fixed

We're writing an application that processes requests using both a normal servlet and a CometProcessor. The normal servlet handles user authentication and logout (among other things). Once the user has been authenticated, the client makes a Comet request, which is open until the server has something to push to the client. When the user decides to log out, we need to stop processing Comet events for that client. I enabled the CometConnectionManagerValve in context.xml, hoping I would get an END event when the session goes away. Instead, I get an IllegalStateException: Mar 10, 2008 2:05:41 PM org.apache.catalina.connector.CoyoteAdapter event SEVERE: An exception or error occurred in the container during the request processing java.lang.IllegalStateException: Cannot create a session after the response has been committed at org.apache.catalina.connector.Request.doGetSession(Request.java:2301) at org.apache.catalina.connector.Request.getSession(Request.java:2075) at org.apache.catalina.valves.CometConnectionManagerValve.event(CometConnectionManagerValve.java:311) at org.apache.catalina.core.StandardHostValve.event(StandardHostValve.java:179) at org.apache.catalina.valves.ValveBase.event(ValveBase.java:200) at org.apache.catalina.core.StandardEngineValve.event(StandardEngineValve.java:128) at org.apache.catalina.connector.CoyoteAdapter.event(CoyoteAdapter.java:198) at org.apache.coyote.http11.Http11NioProcessor.event(Http11NioProcessor.java:749) at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.event(Http11NioProtocol.java:653) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:2080) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907) at java.lang.Thread.run(Thread.java:619) Presumably my servlet handles the "logout" request, and after sending a response to the client, calls invalidate() on the HttpSession. Subsequently, CometConnectionManagerValue.event() calls request.getSession(true), resulting in the IllegalStateException.

Files changed in fix:
java/org/apache/catalina/valves/CometConnectionManagerValve.java