From cfccc6c509ce1bfd9a267f79f303b10871b2c618 Mon Sep 17 00:00:00 2001 From: "Evgeny @ SimpleX Chat" <259188159+evgeny-simplex@users.noreply.github.com> Date: Fri, 29 May 2026 20:28:42 +0000 Subject: [PATCH] do not run thread in background mode --- src/Simplex/Messaging/Agent.hs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Simplex/Messaging/Agent.hs b/src/Simplex/Messaging/Agent.hs index c8deb186c..03af68e87 100644 --- a/src/Simplex/Messaging/Agent.hs +++ b/src/Simplex/Messaging/Agent.hs @@ -273,21 +273,20 @@ getSMPAgentClient_ clientId cfg initServers@InitialAgentServers {smp, xftp, netC env <- ask let processMsg c t = subscriber c t `runReaderT` env c@AgentClient {acThread} <- liftIO $ newAgentClient clientId initServers currentTs notices processMsg env - t <- runAgentThreads c `forkFinally` const (liftIO $ disconnectAgentClient c) - atomically . writeTVar acThread . Just =<< mkWeakThreadId t + unless backgroundMode $ do + t <- runAgentThreads c `forkFinally` const (liftIO $ disconnectAgentClient c) + atomically . writeTVar acThread . Just =<< mkWeakThreadId t pure c checkServers protocol srvs = forM_ (M.assocs srvs) $ \(userId, srvs') -> checkUserServers ("getSMPAgentClient " <> protocol <> " " <> tshow userId) srvs' - runAgentThreads c - | backgroundMode = forever $ liftIO $ threadDelay maxBound - | otherwise = do - restoreServersStats c - raceAny_ - [ run c "runNtfSupervisor" $ runNtfSupervisor c, - run c "cleanupManager" $ cleanupManager c, - run c "logServersStats" $ logServersStats c - ] - `E.finally` saveServersStats c + runAgentThreads c = do + restoreServersStats c + raceAny_ + [ run c "runNtfSupervisor" $ runNtfSupervisor c, + run c "cleanupManager" $ cleanupManager c, + run c "logServersStats" $ logServersStats c + ] + `E.finally` saveServersStats c run AgentClient {subQ, acThread} name a = a `E.catchAny` \e -> whenM (isJust <$> readTVarIO acThread) $ do logError $ "Agent thread " <> name <> " crashed: " <> tshow e