Vaadin 7.6/Tomcat 8 - Dirty UI closings

Vaadin UIs are closed when:

  • the user closes the browser window and three heartbeats are missed,
  • the user goes quiet and the idle session is closed after timeout,
  • the user initiaties an explicit UI close (I provide a button for that).

In any of these circumstances, I am getting the following stack trace a small fraction of the time - maybe one in 20 UI closings. The rest are closed without error. So I suspect a race condition between Vaadin’s push, Tomcat and Atmosphere is taking place at UI closing time. The stack trace indicates:

  • Vaadin calls a disconnect method in AtmospherePushConnection
  • Tomcat/atmosphere tries to write a close message to websocket
  • websocket has already closed so the error is thrown.

Something is being done in the wrong order. Any ideas about how UI closing can always be done cleanly?

Java 8, Tomcat 8.0.30, Vaadin 7.6.0, manual push using websocket, Ubuntu 14.04 java.util.concurrent.ExecutionException: Unable to write the complete message as the WebSocket connection has been closed
    at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.startMessageBlock(
    at org.apache.tomcat.websocket.WsSession.sendCloseMessage(
    at org.apache.tomcat.websocket.WsSession.doClose(
    at org.apache.tomcat.websocket.WsSession.close(
    at org.apache.tomcat.websocket.WsSession.close(
    at org.atmosphere.container.version.JSR356WebSocket.close(
    at org.atmosphere.cpr.AtmosphereResourceImpl.close(
    at com.vaadin.server.communication.AtmospherePushConnection.disconnect(
    at com.vaadin.ui.UI.setPushConnection(
    at com.vaadin.ui.UI.setSession(
    at com.vaadin.server.VaadinSession.removeUI(
    at com.vaadin.server.VaadinService$1$
    at com.vaadin.ui.UI.accessSynchronously(
    at com.vaadin.server.VaadinService$
    at java.util.concurrent.Executors$
    at com.vaadin.server.VaadinService.runPendingAccessTasks(
    at com.vaadin.server.VaadinSession.unlock(
    at com.vaadin.server.VaadinService.requestEnd(
    at com.vaadin.server.VaadinService.handleRequest(
    at com.vaadin.server.VaadinServlet.service(
    at javax.servlet.http.HttpServlet.service(
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(
    at org.apache.catalina.core.StandardWrapperValve.invoke(
    at org.apache.catalina.core.StandardContextValve.invoke(
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(
    at org.apache.catalina.core.StandardHostValve.invoke(
    at org.apache.catalina.valves.ErrorReportValve.invoke(
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(
    at org.apache.catalina.core.StandardEngineValve.invoke(
    at org.apache.catalina.connector.CoyoteAdapter.service(
    at org.apache.coyote.http11.AbstractHttp11Processor.process(
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
    at java.util.concurrent.ThreadPoolExecutor.runWorker(
    at java.util.concurrent.ThreadPoolExecutor$
    at org.apache.tomcat.util.threads.TaskThread$
Caused by: java.util.concurrent.ExecutionException: Unable to write the complete message as the WebSocket connection has been closed
    at org.apache.tomcat.websocket.FutureToSendHandler.get(
    at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.startMessageBlock(
    ... 41 more
Caused by: Unable to write the complete message as the WebSocket connection has been closed
    at org.apache.tomcat.websocket.WsSession.registerFuture(
    at org.apache.tomcat.websocket.FutureToSendHandler.get(
    ... 42 more

Sounds like, track that

Thanks Artur - I’ll follow 19376’s progress.

On a possibly related note, Tomcat 8.0.31 is due to correct, or possibly work around a
closing error
. One poster to that ticket comented:

“Most Websocket clients are quite polite when closing websockets, they will send a close frame and then wait for the handshake before closing the TCP connection.”

I wonder if Vaadin is being “polite”?

Had the same problem. Tomcat 8.0.37 fixed it for me. Possible earlier versions would too.