Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid logging exception for closed session in AbstractSockJsSession #24986

Closed
mbenmass opened this issue Apr 28, 2020 · 4 comments
Closed

Avoid logging exception for closed session in AbstractSockJsSession #24986

mbenmass opened this issue Apr 28, 2020 · 4 comments
Assignees
Labels
in: messaging Issues in messaging modules (jms, messaging) in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Milestone

Comments

@mbenmass
Copy link

mbenmass commented Apr 28, 2020

I have the following WebSocket configuration :

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/game");
        registry.addEndpoint("/game").withSockJS();
    }

    @Override
    public void configureClientInboundChannel(ChannelRegistration registration) {
        registration.interceptors(subscriptionInterceptor());
    }

    @Override
    public void configureClientOutboundChannel(ChannelRegistration registration) {
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/all","/user", "/table");
        config.setApplicationDestinationPrefixes("/app");
        config.setPreservePublishOrder(true);
    }

    @Override
    public void configureWebSocketTransport(WebSocketTransportRegistration registry) {
        registry.setMessageSizeLimit(5 * 1024 * 1024);
        registry.setSendBufferSizeLimit(5 * 1024 * 1024);
        registry.setSendTimeLimit(60 * 1000);
    }

    @Bean
    public SubscriptionInterceptor subscriptionInterceptor() {
        return new SubscriptionInterceptor();
    }
}

I have around 30 JS clients connected to my server using SockJS to send messages. From time to time I get the following error :

ERROR 14607 --- [io-8080-exec-17] .w.s.a.s.StandardWebSocketHandlerAdapter : Closing session due to exception for StandardWebSocketSession[id=11d93b6a-7de1-354b-4f33-5834a89da351, uri=ws://41.250.241.235:8080/game/352/qbd0x4z4/websocket]

org.springframework.web.socket.sockjs.SockJsMessageDeliveryException: Failed to deliver message(s) [SEND
destination:/app/table/7/request/newFrame
content-length:2

{}] for session qbd0x4z4; nested exception is org.springframework.web.socket.sockjs.SockJsMessageDeliveryException: Failed to deliver message(s) [SEND
destination:/app/table/7/request/newFrame
content-length:2

{}] for session qbd0x4z4: Session closed
    at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.delegateMessages(AbstractSockJsSession.java:391) ~[spring-websocket-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession.handleMessage(WebSocketServerSockJsSession.java:195) ~[spring-websocket-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.web.socket.sockjs.transport.handler.SockJsWebSocketHandler.handleTextMessage(SockJsWebSocketHandler.java:93) ~[spring-websocket-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.web.socket.handler.AbstractWebSocketHandler.handleMessage(AbstractWebSocketHandler.java:43) ~[spring-websocket-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.handleTextMessage(StandardWebSocketHandlerAdapter.java:114) [spring-websocket-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.access$000(StandardWebSocketHandlerAdapter.java:43) [spring-websocket-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter$3.onMessage(StandardWebSocketHandlerAdapter.java:85) [spring-websocket-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter$3.onMessage(StandardWebSocketHandlerAdapter.java:82) [spring-websocket-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    at org.apache.tomcat.websocket.WsFrameBase.sendMessageText(WsFrameBase.java:395) [tomcat-embed-websocket-9.0.31.jar:9.0.31]
    at org.apache.tomcat.websocket.server.WsFrameServer.sendMessageText(WsFrameServer.java:119) [tomcat-embed-websocket-9.0.31.jar:9.0.31]
    at org.apache.tomcat.websocket.WsFrameBase.processDataText(WsFrameBase.java:495) [tomcat-embed-websocket-9.0.31.jar:9.0.31]
    at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:294) [tomcat-embed-websocket-9.0.31.jar:9.0.31]
    at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:133) [tomcat-embed-websocket-9.0.31.jar:9.0.31]
    at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:82) [tomcat-embed-websocket-9.0.31.jar:9.0.31]
    at org.apache.tomcat.websocket.server.WsFrameServer.doOnDataAvailable(WsFrameServer.java:171) [tomcat-embed-websocket-9.0.31.jar:9.0.31]
    at org.apache.tomcat.websocket.server.WsFrameServer.notifyDataAvailable(WsFrameServer.java:151) [tomcat-embed-websocket-9.0.31.jar:9.0.31]
    at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.upgradeDispatch(WsHttpUpgradeHandler.java:148) [tomcat-embed-websocket-9.0.31.jar:9.0.31]
    at org.apache.coyote.http11.upgrade.UpgradeProcessorInternal.dispatch(UpgradeProcessorInternal.java:54) [tomcat-embed-core-9.0.31.jar:9.0.31]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:59) [tomcat-embed-core-9.0.31.jar:9.0.31]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-9.0.31.jar:9.0.31]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1639) [tomcat-embed-core-9.0.31.jar:9.0.31]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.31.jar:9.0.31]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_121]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_121]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.31.jar:9.0.31]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]
Caused by: org.springframework.web.socket.sockjs.SockJsMessageDeliveryException: Failed to deliver message(s) [SEND
destination:/app/table/7/request/newFrame
content-length:2

{}] for session qbd0x4z4: Session closed
    at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.delegateMessages(AbstractSockJsSession.java:383) ~[spring-websocket-5.1.14.RELEASE.jar:5.1.14.RELEASE]
    ... 25 common frames omitted

I have no idea why I do get such an error as the logs are not self-explanatory.
I have been looking eveywhere in the internet, but I didn't find any solution to this issue, or at least someone who can explain what is happening.

Grateful if an experienced programmer with Spring and Websocket could help.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 28, 2020
@rstoyanchev
Copy link
Contributor

It means the session was closed simultaneously while a message was being processed and as a result it was dropped. We could avoid throwing the exception there but just do a debug message since there isn't much that could be done.

@rstoyanchev rstoyanchev self-assigned this Apr 30, 2020
@rstoyanchev rstoyanchev added in: messaging Issues in messaging modules (jms, messaging) in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement status: waiting-for-feedback We need additional information before we can continue labels Apr 30, 2020
@mbenmass
Copy link
Author

@rstoyanchev Thanks for your feedback, it makes sense.

Is there a way to catch this exception and avoid displaying it ?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 30, 2020
@rstoyanchev rstoyanchev added this to the 5.2.7 milestone Apr 30, 2020
@rstoyanchev rstoyanchev removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 30, 2020
@rstoyanchev
Copy link
Contributor

We can make sure it's not displayed.

@rstoyanchev rstoyanchev reopened this May 1, 2020
@rstoyanchev
Copy link
Contributor

@mbenmass I intend to make a change for this.

@rstoyanchev rstoyanchev added the for: backport-to-5.1.x Marks an issue as a candidate for backport to 5.1.x label May 1, 2020
@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.1.x Marks an issue as a candidate for backport to 5.1.x labels May 1, 2020
@rstoyanchev rstoyanchev changed the title WebSocket Exception handling in Spring Boot 2.1.13.RELEASE Avoid logging exception for closed session in AbstractSockJsSession May 1, 2020
rstoyanchev added a commit that referenced this issue May 1, 2020
rstoyanchev added a commit that referenced this issue May 4, 2020
zx20110729 pushed a commit to zx20110729/spring-framework that referenced this issue Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: messaging Issues in messaging modules (jms, messaging) in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants