Skip to content

Commit e01398a

Browse files
authored
agent: send MSGNTF on NO_MSG error (#1362)
* agent: send MSGNTF on NO_MSG error * simplify
1 parent f871f20 commit e01398a

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/Simplex/Messaging/Agent.hs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,15 +1684,18 @@ ackQueueMessage :: AgentClient -> RcvQueue -> SMP.MsgId -> AM ()
16841684
ackQueueMessage c rq@RcvQueue {userId, connId, server} srvMsgId = do
16851685
atomically $ incSMPServerStat c userId server ackAttempts
16861686
tryAgentError (sendAck c rq srvMsgId) >>= \case
1687-
Right _ -> do
1688-
atomically $ incSMPServerStat c userId server ackMsgs
1689-
whenM (liftIO $ hasGetLock c rq) $ do
1690-
brokerTs_ <- (Just <$> withStore c (\db -> getRcvMsgBrokerTs db connId srvMsgId)) `catchAgentError` \_ -> pure Nothing
1691-
atomically $ writeTBQueue (subQ c) ("", connId, AEvt SAEConn $ MSGNTF srvMsgId brokerTs_)
1692-
Left (SMP _ SMP.NO_MSG) -> atomically $ incSMPServerStat c userId server ackNoMsgErrs
1687+
Right _ -> sendMsgNtf ackMsgs
1688+
Left (SMP _ SMP.NO_MSG) -> sendMsgNtf ackNoMsgErrs
16931689
Left e -> do
16941690
unless (temporaryOrHostError e) $ atomically $ incSMPServerStat c userId server ackOtherErrs
16951691
throwE e
1692+
where
1693+
sendMsgNtf stat = do
1694+
atomically $ incSMPServerStat c userId server stat
1695+
whenM (liftIO $ hasGetLock c rq) $ do
1696+
atomically $ releaseGetLock c rq
1697+
brokerTs_ <- eitherToMaybe <$> tryAgentError (withStore c $ \db -> getRcvMsgBrokerTs db connId srvMsgId)
1698+
atomically $ writeTBQueue (subQ c) ("", connId, AEvt SAEConn $ MSGNTF srvMsgId brokerTs_)
16961699

16971700
-- | Suspend SMP agent connection (OFF command) in Reader monad
16981701
suspendConnection' :: AgentClient -> ConnId -> AM ()

src/Simplex/Messaging/Agent/Client.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ module Simplex.Messaging.Agent.Client
9292
hasActiveSubscription,
9393
hasPendingSubscription,
9494
hasGetLock,
95+
releaseGetLock,
9596
activeClientSession,
9697
agentClientStore,
9798
agentDRG,
@@ -1647,8 +1648,8 @@ disableQueuesNtfs = sendTSessionBatches "NDEL" snd disableQueues_
16471648

16481649
sendAck :: AgentClient -> RcvQueue -> MsgId -> AM ()
16491650
sendAck c rq@RcvQueue {rcvId, rcvPrivateKey} msgId =
1650-
withSMPClient c rq ("ACK:" <> logSecret' msgId) (\smp -> ackSMPMessage smp rcvPrivateKey rcvId msgId)
1651-
`agentFinally` atomically (releaseGetLock c rq)
1651+
withSMPClient c rq ("ACK:" <> logSecret' msgId) $ \smp ->
1652+
ackSMPMessage smp rcvPrivateKey rcvId msgId
16521653

16531654
hasGetLock :: AgentClient -> RcvQueue -> IO Bool
16541655
hasGetLock c RcvQueue {server, rcvId} =

0 commit comments

Comments
 (0)