From 50ddd630be3727d2860e4ff006a3ba48fdd8c07d Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Wed, 3 Sep 2025 11:12:20 +0100 Subject: [PATCH 1/2] 6.4.5.1 --- simplexmq.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simplexmq.cabal b/simplexmq.cabal index cdbd72c52..69ad73c9a 100644 --- a/simplexmq.cabal +++ b/simplexmq.cabal @@ -1,7 +1,7 @@ cabal-version: 1.12 name: simplexmq -version: 6.4.5.0 +version: 6.4.5.1 synopsis: SimpleXMQ message broker description: This package includes <./docs/Simplex-Messaging-Server.html server>, <./docs/Simplex-Messaging-Client.html client> and From 4386dd8b5aa4a4076795c54d361e4b5a77edca6b Mon Sep 17 00:00:00 2001 From: Evgeny Date: Sun, 7 Sep 2025 09:02:32 +0100 Subject: [PATCH 2/2] smp server: option to expire messages when new message is sent (now off by default) (#1625) * smp server: option to expire messages when new message is sent (now off by default) * fix test --- src/Simplex/Messaging/Protocol.hs | 4 ++-- src/Simplex/Messaging/Server.hs | 10 +++++----- src/Simplex/Messaging/Server/Env/STM.hs | 1 + src/Simplex/Messaging/Server/Main.hs | 1 + src/Simplex/Messaging/Server/Main/Init.hs | 3 ++- tests/SMPClient.hs | 1 + tests/ServerTests.hs | 2 +- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Simplex/Messaging/Protocol.hs b/src/Simplex/Messaging/Protocol.hs index ced27bae2..e5d918cc6 100644 --- a/src/Simplex/Messaging/Protocol.hs +++ b/src/Simplex/Messaging/Protocol.hs @@ -2022,7 +2022,7 @@ instance Encoding BrokerErrorType where RESPONSE e -> "RESPONSE " <> smpEncode e UNEXPECTED e -> "UNEXPECTED " <> smpEncode e TRANSPORT e -> "TRANSPORT " <> smpEncode e - NETWORK e -> "NETWORK" -- TODO once all upgrade: "NETWORK " <> smpEncode e + NETWORK _e -> "NETWORK" -- TODO once all upgrade: "NETWORK " <> smpEncode e TIMEOUT -> "TIMEOUT" HOST -> "HOST" NO_SERVICE -> "NO_SERVICE" @@ -2042,7 +2042,7 @@ instance StrEncoding BrokerErrorType where RESPONSE e -> "RESPONSE " <> encodeUtf8 (T.pack e) UNEXPECTED e -> "UNEXPECTED " <> encodeUtf8 (T.pack e) TRANSPORT e -> "TRANSPORT " <> smpEncode e - NETWORK e -> "NETWORK" -- TODO once all upgrade: "NETWORK " <> strEncode e + NETWORK _e -> "NETWORK" -- TODO once all upgrade: "NETWORK " <> strEncode e TIMEOUT -> "TIMEOUT" HOST -> "HOST" NO_SERVICE -> "NO_SERVICE" diff --git a/src/Simplex/Messaging/Server.hs b/src/Simplex/Messaging/Server.hs index 9ca6856ee..23ce85035 100644 --- a/src/Simplex/Messaging/Server.hs +++ b/src/Simplex/Messaging/Server.hs @@ -1848,10 +1848,10 @@ client Right body -> do when (isJust (queueData qr) && isSecuredMsgQueue qr) $ void $ liftIO $ deleteQueueLinkData (queueStore ms) q - ServerConfig {messageExpiration, msgIdBytes} <- asks config + ServerConfig {messageExpiration, expireMessagesOnSend, msgIdBytes} <- asks config msgId <- randomId' msgIdBytes msg_ <- liftIO $ runExceptT $ do - expireMessages messageExpiration stats + when expireMessagesOnSend $ mapM_ (expireMessages stats) messageExpiration msg <- liftIO $ mkMessage msgId body writeMsg ms q True msg case msg_ of @@ -1875,9 +1875,9 @@ client msgTs <- getSystemTime pure $! Message msgId msgTs msgFlags body - expireMessages :: Maybe ExpirationConfig -> ServerStats -> ExceptT ErrorType IO () - expireMessages msgExp stats = do - deleted <- maybe (pure 0) (deleteExpiredMsgs ms q <=< liftIO . expireBeforeEpoch) msgExp + expireMessages :: ServerStats -> ExpirationConfig -> ExceptT ErrorType IO () + expireMessages stats msgExp = do + deleted <- deleteExpiredMsgs ms q =<< liftIO (expireBeforeEpoch msgExp) liftIO $ when (deleted > 0) $ atomicModifyIORef'_ (msgExpired stats) (+ deleted) -- The condition for delivery of the message is: diff --git a/src/Simplex/Messaging/Server/Env/STM.hs b/src/Simplex/Messaging/Server/Env/STM.hs index d0f1a84fd..3bc535b8c 100644 --- a/src/Simplex/Messaging/Server/Env/STM.hs +++ b/src/Simplex/Messaging/Server/Env/STM.hs @@ -153,6 +153,7 @@ data ServerConfig s = ServerConfig -- | time after which the messages can be removed from the queues and check interval, seconds messageExpiration :: Maybe ExpirationConfig, expireMessagesOnStart :: Bool, + expireMessagesOnSend :: Bool, -- | interval of inactivity after which journal queue is closed idleQueueInterval :: Int64, -- | notification expiration interval (seconds) diff --git a/src/Simplex/Messaging/Server/Main.hs b/src/Simplex/Messaging/Server/Main.hs index f94cd9682..90fe52d06 100644 --- a/src/Simplex/Messaging/Server/Main.hs +++ b/src/Simplex/Messaging/Server/Main.hs @@ -428,6 +428,7 @@ smpServerCLI_ generateSite serveStaticFiles attachStaticFiles cfgPath logPath = { ttl = 86400 * readIniDefault defMsgExpirationDays "STORE_LOG" "expire_messages_days" ini }, expireMessagesOnStart = fromMaybe True $ iniOnOff "STORE_LOG" "expire_messages_on_start" ini, + expireMessagesOnSend = fromMaybe True $ iniOnOff "STORE_LOG" "expire_messages_on_send" ini, idleQueueInterval = defaultIdleQueueInterval, notificationExpiration = defaultNtfExpiration diff --git a/src/Simplex/Messaging/Server/Main/Init.hs b/src/Simplex/Messaging/Server/Main/Init.hs index 2823df74f..d17018de2 100644 --- a/src/Simplex/Messaging/Server/Main/Init.hs +++ b/src/Simplex/Messaging/Server/Main/Init.hs @@ -87,7 +87,8 @@ iniFileContent cfgPath logPath opts host basicAuth controlPortPwds = <> ("restore_messages: " <> onOff enableStoreLog <> "\n\n") <> "# Messages and notifications expiration periods.\n" <> ("expire_messages_days: " <> tshow defMsgExpirationDays <> "\n") - <> "expire_messages_on_start: on\n" + <> "expire_messages_on_start: on\n\ + \expire_messages_on_send: off\n" <> ("expire_ntfs_hours: " <> tshow defNtfExpirationHours <> "\n\n") <> "# Log daily server statistics to CSV file\n" <> ("log_stats: " <> onOff logStats <> "\n\n") diff --git a/tests/SMPClient.hs b/tests/SMPClient.hs index 2b18a2d51..1f867744a 100644 --- a/tests/SMPClient.hs +++ b/tests/SMPClient.hs @@ -229,6 +229,7 @@ cfgMS msType = withStoreCfg (testServerStoreConfig msType) $ \serverStoreCfg -> dailyBlockQueueQuota = 20, messageExpiration = Just defaultMessageExpiration, expireMessagesOnStart = True, + expireMessagesOnSend = False, idleQueueInterval = defaultIdleQueueInterval, notificationExpiration = defaultNtfExpiration, inactiveClientExpiration = Just defaultInactiveClientExpiration, diff --git a/tests/ServerTests.hs b/tests/ServerTests.hs index 649d259d7..204365931 100644 --- a/tests/ServerTests.hs +++ b/tests/ServerTests.hs @@ -1205,7 +1205,7 @@ testMsgExpireOnSend = it "should expire messages that are not received before messageTTL on SEND" $ \(ATransport (t :: TProxy c 'TServer), msType) -> do g <- C.newRandom (sPub, sKey) <- atomically $ C.generateAuthKeyPair C.SEd25519 g - let cfg' = updateCfg (cfgMS msType) $ \cfg_ -> cfg_ {messageExpiration = Just ExpirationConfig {ttl = 1, checkInterval = 10000}} + let cfg' = updateCfg (cfgMS msType) $ \cfg_ -> cfg_ {expireMessagesOnSend = True, messageExpiration = Just ExpirationConfig {ttl = 1, checkInterval = 10000}} withSmpServerConfigOn (ATransport t) cfg' testPort $ \_ -> testSMPClient @c $ \sh -> do (sId, rId, rKey, dhShared) <- testSMPClient @c $ \rh -> createAndSecureQueue rh sPub