Skip to content

Commit d2eaf3c

Browse files
committed
Fix reconnect issue in WebSocketGraphQlTransport
Closes gh-826
1 parent eee7f09 commit d2eaf3c

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

spring-graphql/src/main/java/org/springframework/graphql/client/WebSocketGraphQlTransport.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,15 @@ private static Mono<GraphQlSession> initGraphQlSession(
9696
return Mono.error(new IllegalStateException("WebSocketGraphQlTransport has been stopped"));
9797
}
9898

99+
// Get the session Mono before connecting
100+
Mono<GraphQlSession> sessionMono = handler.getGraphQlSession();
101+
99102
client.execute(uri, headers, handler)
100-
.subscribe(aVoid -> {}, handler::handleWebSocketSessionError, () -> {});
103+
.subscribe(aVoid -> {},
104+
handler::handleWebSocketSessionError,
105+
handler::handleWebSocketSessionClosed);
101106

102-
return handler.getGraphQlSession();
107+
return sessionMono;
103108
});
104109
}
105110

@@ -311,10 +316,6 @@ private void registerCloseStatusHandling(GraphQlSession graphQlSession, WebSocke
311316
}
312317
graphQlSession.terminateRequests(closeStatusMessage, closeStatus);
313318
})
314-
.doOnTerminate(() -> {
315-
// Reset GraphQlSession sink to be ready to connect again
316-
this.graphQlSessionSink = Sinks.unsafe().one();
317-
})
318319
.subscribe();
319320
}
320321

@@ -356,6 +357,15 @@ else if (logger.isErrorEnabled()) {
356357
}
357358

358359
this.graphQlSessionSink.tryEmitError(ex);
360+
this.graphQlSessionSink = Sinks.unsafe().one();
361+
}
362+
363+
/**
364+
* This must be called from code that calls the {@code WebSocketClient}
365+
* when execution completes.
366+
*/
367+
public void handleWebSocketSessionClosed() {
368+
this.graphQlSessionSink = Sinks.unsafe().one();
359369
}
360370

361371
}

0 commit comments

Comments
 (0)