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
This commit is contained in:
rstoyanchev
2023-09-15 16:59:19 +01:00
parent e48004f0bf
commit 9d34402545

View File

@@ -213,7 +213,15 @@ public class GraphQlWebSocketHandler extends TextWebSocketHandler implements Sub
.publishOn(state.getScheduler()) // Serial blocking send via single thread
.subscribe(new SendMessageSubscriber(id, session, state));
}
case PING -> session.sendMessage(encode(GraphQlWebSocketMessage.pong(null)));
case PING ->
state.getScheduler().schedule(() -> {
try {
session.sendMessage(encode(GraphQlWebSocketMessage.pong(null)));
}
catch (IOException ex) {
ExceptionWebSocketHandlerDecorator.tryCloseWithError(session, ex, logger);
}
});
case COMPLETE -> {
if (id != null) {
Subscription subscription = state.getSubscriptions().remove(id);