Unable to write the complete message as the WebSocket connection has been c

We have Vaadin Push enabled with @Push(transport = Transport.WEBSOCKET_XHR). When UI is detached, we see the below exception at the log.

Seems like it does not impact anything other than errors at the log. Do you know how to close the connection nicely so we do not fill the log with those errors?

Thank you in advance.

07:33:40.853 [http-nio-8080-exec-7]
ERROR o.a.container.JSR356Endpoint/log java.io.IOException: Unable to write the complete message as the WebSocket connection has been closed at org.apache.tomcat.websocket.WsSession.registerFuture(WsSession.java:664) at org.apache.tomcat.websocket.FutureToSendHandler.get(FutureToSendHandler.java:92) at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.startMessageBlock(WsRemoteEndpointImplBase.java:277) at org.apache.tomcat.websocket.WsSession.sendCloseMessage(WsSession.java:586) at org.apache.tomcat.websocket.WsSession.doClose(WsSession.java:488) at org.apache.tomcat.websocket.WsSession.close(WsSession.java:455) at org.apache.tomcat.websocket.WsSession.close(WsSession.java:449) at org.atmosphere.container.version.JSR356WebSocket.close(JSR356WebSocket.java:142) at org.atmosphere.cpr.AtmosphereResourceImpl.close(AtmosphereResourceImpl.java:860) at com.vaadin.server.communication.ArePushConnection.disconnect(AtmospherePushConnection.java:312) at com.bast.gp.cube.seq.vaadinui.MyVaadinUI.detach(MyVaadinUI.java:111) at com.vaadin.ui.UI.setSession(UI.java:465) at com.vaadin.server.VaadinSession.removeUI(VaadinSession.java:870) at com.vaadin.server.VaadinService$1$1.run(VaadinService.java:481) at com.vaadin.ui.UI.accessSynchronously(UI.java:1381) at com.vaadin.server.VaadinService$1.run(VaadinService.java:469) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at com.vaadin.server.VaadinService.runPendingAccessTasks(VaadinService.java:1835) at com.vaadin.server.VaadinSession.unlock(VaadinSession.java:990) at com.vaadin.server.VaadinService.requestEnd(VaadinService.java:1356) at org.vaadin.spring.servlet.Vaadin4SpringServletService.requestEnd(Vaadin4SpringServletService.java:84) at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1423) at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:364) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextHeaderFilter.doFilterInternal(EndpointWebMvcAutoConfiguration.java:237) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(AppliclterChain.java:207) at org.vaadin.spring.http.HttpResponseFilter.doFilter(HttpResponseFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.springframework.security.oauth2.client.filter.OAuth2ClientContextFilter.doFilter(OAuth2ClientContextFilter.java:60) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:48) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:112) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:316) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:126) at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:122) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:48) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:120) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:91) at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:53) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.springframework.security.web.FilterChainProxy$VirtualFilterChaiter(FilterChainProxy.java:330) at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213) at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176) at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:103) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) 07:33:41.209 [http-nio-8080-exec-7]
DEBUG c.vaadin.spring.internal.UIScopeImpl/detach UI [com.bast.gp.cube.seq.vaadinui.MyVaadinUI@a27a41e]
has been detached, destroying [UIBeanStore [id=4df03526, name=UI:0]
] 07:33:41.210 [http-nio-8080-exec-7]
DEBUG com.vaadin.spring.internal.BeanStore/destroy Destroying [UIBeanStore[id=4df03526, name=UI:0]
] 07:33:41.211 [http-nio-8080-exec-7]
DEBUG c.v.s.internal.UIScopeImpl$UIStore/sessionDestroy Vaadin session has been destroyed, destroying [UIStore[id=36f84595, sessionId=55AF0F6E983B 2291A8F9DBE9AA370163]
] 07:33:41.212 [http-nio-8080-exec-7]
DEBUG c.v.s.i.VaadinSessionScope$SessionAwareBeanStore/sessionDestroy Vaadin session has been destroyed, destroying [SessionAwareBeanStore[id=6275 7279, name=Session:55AF0F6E983B2291A8F9DBE9AA370163]
]
spring-boot vaadin vaadin-push

I think you’ll find that Tomcat has just addressed that one in 8.0.33 with
this
fix. My logs have gone from 50% close-related stack traces to clean following the upgrade.

Thank you for your reply Steve. We use Spring Boot 1.3.3 and it uses Tomcat 8 by default. Maybe I am wrong, I will check again.

We have the above exception when user logs off or other times when the current UI is detached. Was that your experinece as well?

That was exacty my experience. No user was ever affected as the error occured when the user was disconnecting - closing the browser window, timing out or navigating away from a mobile browser. The next login was normal so the user never saw it.

As far as I know, the problem affected all Tomcat 8 releases (it first appeared in a point upgrade of Tomcat 7). It has been fixed only a couple days ago in Tomcat 7.0.69 and 8.0.33. If you haven’t upgraded to the latest Tomcat this week by downloading the latest source, you won’t have the fix.

Yes, you are correct Steve. Spring uses Tomcat 8.0.32 by default.

I needed to upgrade 8.0.33 to overcome this issue, and this is how I managed to change Tomcat version for Spring Boot v1.3.3 and Gradle.

compile("org.springframework.boot:spring-boot-starter-web") { exclude module: "spring-boot-starter-tomcat" } //Because of the websocket defect on tomcat, I comment out the below line //providedRuntime("org.springframework.boot:spring-boot-starter-tomcat") compile 'org.apache.tomcat.embed:tomcat-embed-core:8.0.33' compile 'org.apache.tomcat.embed:tomcat-embed-el:8.0.33' compile 'org.apache.tomcat.embed:tomcat-embed-logging-juli:8.0.33' compile 'org.apache.tomcat.embed:tomcat-embed-websocket:8.0.33' Thank you very much for the help Steve.
Turgos

FWIW, I’m still seeing a similar, but different error in Tomcat. I’ve seen these using APR, NIO nad NIO2 connectors. I submitted a new bug report to Tomcat on it :
59253
. The stack trace and error description seems similar in structure to the one fixed in 8.0.33, so I’m hoping Tomcat developers might find a familiar solution. I lack the skills to diagnose it further.

Mar 30, 2016 3:29:06 PM org.atmosphere.container.JSR356Endpoint onError

SEVERE: 

java.io.IOException: Unexpected error [120,005]
 reading data from the APR/native socket [139,838,766,510,368]
 with wrapper [org.apache.tomcat.util.net.AprEndpoint$AprSocketWrapper@35e81a8b:139838766510368]
.
    at org.apache.coyote.http11.upgrade.AprServletInputStream.doRead(AprServletInputStream.java:133)
    at org.apache.coyote.http11.upgrade.AbstractServletInputStream.read(AbstractServletInputStream.java:124)
    at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:60)
    at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler$WsReadListener.onDataAvailable(WsHttpUpgradeHandler.java:186)
    at org.apache.coyote.http11.upgrade.AbstractServletInputStream.onDataAvailable(AbstractServletInputStream.java:198)
    at org.apache.coyote.http11.upgrade.AbstractProcessor.upgradeDispatch(AbstractProcessor.java:96)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:647)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2500)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2489)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)