Skip to content

Commit 9d34402

Browse files
committed
Send Pong via scheduler for the session
Single threaded scheduler for serial sending, avoiding concurrent sends that are not allowed by the WebSocket runtime. Closes gh-793
1 parent e48004f commit 9d34402

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlWebSocketHandler.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,15 @@ private void handleInternal(WebSocketSession session, TextMessage webSocketMessa
213213
.publishOn(state.getScheduler()) // Serial blocking send via single thread
214214
.subscribe(new SendMessageSubscriber(id, session, state));
215215
}
216-
case PING -> session.sendMessage(encode(GraphQlWebSocketMessage.pong(null)));
216+
case PING ->
217+
state.getScheduler().schedule(() -> {
218+
try {
219+
session.sendMessage(encode(GraphQlWebSocketMessage.pong(null)));
220+
}
221+
catch (IOException ex) {
222+
ExceptionWebSocketHandlerDecorator.tryCloseWithError(session, ex, logger);
223+
}
224+
});
217225
case COMPLETE -> {
218226
if (id != null) {
219227
Subscription subscription = state.getSubscriptions().remove(id);

0 commit comments

Comments
 (0)