Improve cancellation of read/write inactivity

The cancellation of read and write inactivity tasks was done via
WebSocketHandler#afterConnectionClosed, relying on the WebSocket
library to always invoke the callback.

This change moves the cancellation to the `close` method instead
that in turn is called from DefaultStompSession#resetConnection,
in effect making the cancellation more proactive and aligned with
connection cleanup in DefaultStompSession vs relying on a
subsequent call from the WebSocket library after the connection
is closed.

Closes gh-32195
This commit is contained in:
rstoyanchev
2024-02-13 11:16:26 +00:00
parent 6be0432e3d
commit 2dd22f64e1
2 changed files with 38 additions and 22 deletions

View File

@@ -302,7 +302,9 @@ class WebSocketStompClientTests {
tcpConnection.onReadInactivity(mock(), 2L);
tcpConnection.onWriteInactivity(mock(), 2L);
this.webSocketHandlerCaptor.getValue().afterConnectionClosed(this.webSocketSession, CloseStatus.NORMAL);
WebSocketHandler handler = this.webSocketHandlerCaptor.getValue();
TcpConnection<?> connection = (TcpConnection<?>) WebSocketHandlerDecorator.unwrap(handler);
connection.close();
verify(future, times(2)).cancel(true);
verifyNoMoreInteractions(future);