From 8aa75be0d321ca84044306589a813a18394fc008 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Fri, 2 Feb 2024 03:34:11 +0100 Subject: [PATCH] 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. --- .../server/subscriptions/ApolloSubscriptionProtocolHandler.kt | 1 + .../server/subscriptions/ApolloSubscriptionSessionState.kt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/subscriptions/ApolloSubscriptionProtocolHandler.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/subscriptions/ApolloSubscriptionProtocolHandler.kt index 15dc9941e..174173fbf 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/subscriptions/ApolloSubscriptionProtocolHandler.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/subscriptions/ApolloSubscriptionProtocolHandler.kt @@ -178,6 +178,7 @@ class ApolloSubscriptionProtocolHandler( } private fun onDisconnect(context: WsContext): Flow { + logger.debug("Session \"${context.sessionId}\" disconnected") sessionState.terminateSession(context, CloseStatus(1000, "Normal Closure")) return emptyFlow() } diff --git a/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/subscriptions/ApolloSubscriptionSessionState.kt b/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/subscriptions/ApolloSubscriptionSessionState.kt index ea58b56af..50dff9498 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/subscriptions/ApolloSubscriptionSessionState.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/graphql/server/subscriptions/ApolloSubscriptionSessionState.kt @@ -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)