Project: Tomcat
Bug 54724 WsSession does not throw IllegalStateException if closed when methods on it are called
Reported: 2013-03-19 13:22:56 | Status: resolved fixed

Spec JavaDoc says: "Once the session is closed, it is no longer valid for use by applications. Calling any of its methods once the session has been closed will result in an IllegalStateException being thrown. Developers should retrieve any information from the session during the Endpoint.onClose(Session, CloseReason) method." Of course, the rules of Closeable also apply here, and calling Session#close(...) more than once should have no effect subsequent times. There are actually three problems here: 1) None of the methods throw IllegalStateException if the session is closed. Instead, they return things (like the basic remote, for example), and some methods in the endpoint implementation will not notice concurrent exceptions from the socket and then block forever waiting four the Countdown to clear. 2) The Session#state is never actually changed to State.CLOSED unless Session#onClose is called. However, Session#onClose is never actually called that I can find (though I will look harder before I make changes). 3) Even in Session#onClose, the state is incorrectly changed to State.CLOSED BEFORE Endpoint#onClose is called, when it should be changed AFTER. I'm working on a patch for this.

Files changed in fix:
java/org/apache/tomcat/websocket/WsSession.java test/org/apache/tomcat/websocket/TestWsWebSocketContainer.java