From 96c633930666ab52db97fe600e23b98a515161a6 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sun, 29 Aug 2021 13:10:59 +0100 Subject: [PATCH] fix error handling of sending pending messages; set block size to 8192 (#184) * fix error handling of sending pending messages * s/tryAction/tryError/ --- src/Simplex/Messaging/Agent.hs | 21 +++++++++++---------- src/Simplex/Messaging/Transport.hs | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Simplex/Messaging/Agent.hs b/src/Simplex/Messaging/Agent.hs index 100f4675f..76145ec0a 100644 --- a/src/Simplex/Messaging/Agent.hs +++ b/src/Simplex/Messaging/Agent.hs @@ -403,21 +403,22 @@ runSrvMsgDelivery c@AgentClient {subQ} srv = do forever $ do PendingMsg {connId, msgId} <- atomically $ readTQueue mq let mId = unId msgId - r <- withStore $ \st -> - (Right <$> getPendingMsgData st connId msgId) - `E.catch` \(e :: E.SomeException) -> pure $ Left e - case r of - Left e -> notify connId $ MERR mId (INTERNAL $ show e) + withStore (\st -> E.try $ getPendingMsgData st connId msgId) >>= \case + Left (e :: E.SomeException) -> + notify connId $ MERR mId (INTERNAL $ show e) Right (sq, msgBody) -> do withRetryInterval ri $ \loop -> do - sendAgentMessage c sq msgBody - `catchError` \case + tryError (sendAgentMessage c sq msgBody) >>= \case + Left e -> case e of SMP SMP.QUOTA -> loop - e@SMP {} -> notify connId $ MERR mId e + SMP {} -> notify connId $ MERR mId e + CMD {} -> notify connId $ MERR mId e _ -> loop - notify connId $ SENT mId - withStore $ \st -> updateSndMsgStatus st connId msgId SndMsgSent + Right () -> do + notify connId $ SENT mId + withStore $ \st -> updateSndMsgStatus st connId msgId SndMsgSent where + tryError action = (Right <$> action) `catchError` (pure . Left) notify :: ConnId -> ACommand 'Agent -> m () notify connId cmd = atomically $ writeTBQueue subQ ("", connId, cmd) diff --git a/src/Simplex/Messaging/Transport.hs b/src/Simplex/Messaging/Transport.hs index 18e05260b..590995a4f 100644 --- a/src/Simplex/Messaging/Transport.hs +++ b/src/Simplex/Messaging/Transport.hs @@ -427,7 +427,7 @@ binaryRsaTransport :: Int binaryRsaTransport = 0 transportBlockSize :: Int -transportBlockSize = 4096 +transportBlockSize = 8192 maxTransportBlockSize :: Int maxTransportBlockSize = 65536