From d1b3b5ff544cce0dacf9ccb54ed1311f837be41f Mon Sep 17 00:00:00 2001 From: IC Rainbow Date: Mon, 6 May 2024 20:21:05 +0300 Subject: [PATCH] remove from client subs when removing conn --- src/Simplex/Messaging/Agent.hs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Simplex/Messaging/Agent.hs b/src/Simplex/Messaging/Agent.hs index f8ef4d5b9..d79df96bb 100644 --- a/src/Simplex/Messaging/Agent.hs +++ b/src/Simplex/Messaging/Agent.hs @@ -1623,6 +1623,12 @@ prepareDeleteConnections_ getConnections c waitDelivery connIds = do rqs = concat $ M.elems rcvQs connIds' = M.keys rcvQs lift . forM_ connIds' $ disableConn c + -- remove from subs tracking in clients + clients <- readTVarIO (smpClients c) + forM_ clients $ \SessionVar {sessionVar} -> + atomically $ tryReadTMVar sessionVar >>= \case + Just (Right smp) -> modifyTVar' (sentSubs smp) . M.filterWithKey $ \k _v -> k `M.notMember` rcvQs + _ -> pure () -- ! delRs is not used to notify about the result in any of the calling functions, -- ! it is only used to check results count in deleteConnections_; -- ! if it was used to notify about the result, it might be necessary to differentiate @@ -2246,6 +2252,7 @@ processSMPTransmission c@AgentClient {smpClients, subQ} (tSess@(_, srv, _), _v, Just (Right clnt) | sessId == sessionId (thParams clnt) -> do removeSubscription c connId + modifyTVar (sentSubs clnt) $ M.delete connId notify' END pure "END" | otherwise -> ignored