diff --git a/src/Simplex/Messaging/Agent.hs b/src/Simplex/Messaging/Agent.hs index 011d4128c..5ef3ab9b8 100644 --- a/src/Simplex/Messaging/Agent.hs +++ b/src/Simplex/Messaging/Agent.hs @@ -2240,7 +2240,7 @@ processSMPTransmission c@AgentClient {smpClients, subQ} (tSess@(_, srv, _), _v, ((&&) <$> hasPendingSubscription c connId <*> activeClientSession c tSess sessId) (True <$ addSubscription c rq) (pure False) - when added . notify $ UP srv [connId] + when (added && isResponse) $ notify $ UP srv [connId] decryptClientMessage :: C.DhSecretX25519 -> SMP.ClientMsgEnvelope -> AM (SMP.PrivHeader, AgentMsgEnvelope) decryptClientMessage e2eDh SMP.ClientMsgEnvelope {cmNonce, cmEncBody} = do diff --git a/src/Simplex/Messaging/Agent/Client.hs b/src/Simplex/Messaging/Agent/Client.hs index 73c67dddb..86df3a2af 100644 --- a/src/Simplex/Messaging/Agent/Client.hs +++ b/src/Simplex/Messaging/Agent/Client.hs @@ -1177,20 +1177,22 @@ subscribeQueues c qs = do subscribeQueues_ :: Env -> TVar (Maybe SessionId) -> SMPClient -> NonEmpty RcvQueue -> IO (BatchResponses SMPClientError ()) subscribeQueues_ env session smp qs' = do rs <- sendBatch subscribeSMPQueues smp qs' - let tSess = transportSession' smp - sessId = sessionId $ thParams smp - active <- + active <- atomically $ ifM (activeClientSession c tSess sessId) (writeTVar session (Just sessId) >> mapM_ (uncurry $ processSubResult c) rs $> True) (pure False) - when (active || hasTempErrors rs) $ - resubscribeSMPSession c tSess `runReaderT` env - unless active $ logWarn "subcription batch result for replaced SMP client, resubscribing" - pure rs + if active + then when (hasTempErrors rs) resubscribe $> rs + else do + unless active $ logWarn "subcription batch result for replaced SMP client, resubscribing" + resubscribe $> L.map (second $ \_ -> Left PCENetworkError) rs where + tSess = transportSession' smp + sessId = sessionId $ thParams smp hasTempErrors = any (either temporaryClientError (const False) . snd) + resubscribe = resubscribeSMPSession c tSess `runReaderT` env activeClientSession :: AgentClient -> SMPTransportSession -> SessionId -> STM Bool activeClientSession c tSess sessId = sameSess <$> tryReadSessVar tSess (smpClients c) diff --git a/tests/AgentTests/FunctionalAPITests.hs b/tests/AgentTests/FunctionalAPITests.hs index 8cea3a30a..cb4f9bb55 100644 --- a/tests/AgentTests/FunctionalAPITests.hs +++ b/tests/AgentTests/FunctionalAPITests.hs @@ -2581,7 +2581,6 @@ testTwoUsers = withAgentClients2 $ \a b -> do ("", "", UP _ _) <- nGet a ("", "", UP _ _) <- nGet a a `hasClients` 1 - ("", "", UP _ _) <- nGet a aUserId2 <- createUser a [noAuthSrv testSMPServer] [noAuthSrv testXFTPServer] (aId2, bId2) <- makeConnectionForUsers a aUserId2 b 1 @@ -2613,8 +2612,6 @@ testTwoUsers = withAgentClients2 $ \a b -> do ("", "", UP _ _) <- nGet a ("", "", UP _ _) <- nGet a a `hasClients` 2 - ("", "", UP _ _) <- nGet a - ("", "", UP _ _) <- nGet a exchangeGreetingsMsgId 10 a bId1 b aId1 exchangeGreetingsMsgId 10 a bId1' b aId1' exchangeGreetingsMsgId 8 a bId2 b aId2