Cleanup gql subscription session state correctly (#859)

In case a socket got disconnected, the session state of the subscriptions did not get correctly cleaned up.
The active operations did get closed but not removed and thus, when the client tried to reconnect, the server incorrectly detected an active subscription for an operation and immediately terminated the subscription.
This commit is contained in:
schroda
2024-02-02 03:34:11 +01:00
committed by GitHub
parent dc124fb15c
commit 8aa75be0d3
2 changed files with 2 additions and 1 deletions

View File

@@ -178,6 +178,7 @@ class ApolloSubscriptionProtocolHandler(
}
private fun onDisconnect(context: WsContext): Flow<SubscriptionOperationMessage> {
logger.debug("Session \"${context.sessionId}\" disconnected")
sessionState.terminateSession(context, CloseStatus(1000, "Normal Closure"))
return emptyFlow()
}

View File

@@ -90,7 +90,7 @@ internal class ApolloSubscriptionSessionState {
code: CloseStatus,
) {
sessionToOperationId.remove(context.sessionId)?.forEach {
activeOperations[it]?.cancel()
removeActiveOperation(it)
}
cachedGraphQLContext.remove(context.sessionId)
context.closeSession(code)