Fix IllegalArgumentException that prevents STOMP DISCONNECT from reaching the client#30120
Closed
alexjansons wants to merge 1 commit intospring-projects:mainfrom
Closed
Fix IllegalArgumentException that prevents STOMP DISCONNECT from reaching the client#30120alexjansons wants to merge 1 commit intospring-projects:mainfrom
alexjansons wants to merge 1 commit intospring-projects:mainfrom
Conversation
In some application setups, the WebSocket server does not transmit the disconnect message to the client, so that the client has no idea that the established connection has been terminated. This issue arises when the application uses SimpleBrokerMessageHandler and the error handler is set to the instance of StompSubProtocolErrorHandler or an extended class that does not override the handleErrorMessageToClient method. The commit fixes disconnect message population so that `java.lang.IllegalArgumentException: No StompHeaderAccessor` exception is not thrown in the handleErrorMessageToClient method in StompSubProtocolErrorHandler class.
e3cdd8d to
cb785e1
Compare
simonbasle
suggested changes
Mar 22, 2023
Contributor
simonbasle
left a comment
There was a problem hiding this comment.
hey @alexjansons, thanks for the PR! Would you be able to produce a unit test or compact integration test that reproduces the issue and validates the fix?
| if (StompCommand.ERROR.equals(command) && getErrorHandler() != null) { | ||
| Message<byte[]> errorMessage = getErrorHandler().handleErrorMessageToClient((Message<byte[]>) message); | ||
| Message<byte[]> enrichedMessage = | ||
| MessageBuilder.createMessage((byte[]) message.getPayload(), accessor.getMessageHeaders()); |
Contributor
There was a problem hiding this comment.
nit: rather than casting, you can use payload from the instanceOf at the top
rstoyanchev
pushed a commit
that referenced
this pull request
Apr 11, 2023
In some application setups, the WebSocket server does not transmit the disconnect message to the client, so that the client has no idea that the established connection has been terminated. This issue arises when the application uses SimpleBrokerMessageHandler and the error handler is set to the instance of StompSubProtocolErrorHandler or an extended class that does not override the handleErrorMessageToClient method. The commit fixes disconnect message population so that `java.lang.IllegalArgumentException: No StompHeaderAccessor` exception is not thrown in the handleErrorMessageToClient method in StompSubProtocolErrorHandler class. See gh-30120
izeye
added a commit
to izeye/spring-framework
that referenced
this pull request
Apr 19, 2023
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In some application setups, the WebSocket server does not transmit the disconnect message to the client, so that the client has no idea that the established connection has been terminated.
This issue arises when the application uses SimpleBrokerMessageHandler and the error handler is set to the instance of
StompSubProtocolErrorHandler or an extended class that does not override the handleErrorMessageToClient method.
The commit fixes disconnect message population so that
java.lang.IllegalArgumentException: No StompHeaderAccessorexception is not thrown in the handleErrorMessageToClient method in StompSubProtocolErrorHandler class.A reproducible example for the case is available here:
The issue arises when the client fails to send heartbeats for specific period, causing the server to terminate the session by invoking the
handleDisconnectmethod in theSimpleBrokerMessageHandler.HeartbeatTaskclass. This issue was discovered in spring-websocket-5.3.13 but still persists in the latest code base.If the error handler is not set, then there is no problem as the message is delivered to the client in this scenario. A reproducible example that illustrates this is the
DisconnectWithoutErrorHandler.testfound at https://github.com/alexjansons/spring-sandbox/blob/main/web-socket/disconnect-error/src/test/java/com/example/websocket/disconnecterror/ApplicationTests.java#L97.However if the error handler is set to
StompSubProtocolErrorHandlerclass instance or the instance of extended class given that the latter does not implement it's ownhandleErrorMessageToClientmethod, the disconnect message transmission process faces theIllegalArgumentExceptionexception in the aforementioned method. The exception is caught and then silently ignored inSubProtocolWebSocketHandler.handleMessagemethod, which results in no message being sent to the client. This case is covered inDisconnectWithErrorHandler.testat https://github.com/alexjansons/spring-sandbox/blob/main/web-socket/disconnect-error/src/test/java/com/example/websocket/disconnecterror/ApplicationTests.java#L83.A workaround for this issue is to extend the
StompSubProtocolErrorHandlerclass for the error handler and re-implement the methodhandleErrorMessageToClientso that it does not generate an exception. An example of this workaround can be found at https://github.com/alexjansons/spring-sandbox/blob/main/web-socket/disconnect-error/src/main/java/com/example/websocket/disconnecterror/Application.java#L24.