Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catch errors in cleanup manager #698

Merged
merged 4 commits into from
Mar 27, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/Simplex/Messaging/Agent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1610,32 +1610,33 @@ subscriber c@AgentClient {msgQ} = forever $ do
Left e -> liftIO $ print e
Right _ -> return ()

cleanupManager :: AgentMonad' m => AgentClient -> m ()
cleanupManager c = do
cleanupManager :: forall m. AgentMonad' m => AgentClient -> m ()
cleanupManager c@AgentClient {subQ} = do
threadDelay =<< asks (initialCleanupDelay . config)
int <- asks (cleanupInterval . config)
forever $ do
void . runExceptT $ do
deleteConns
deleteFiles
threadDelay int
deleteConns `catchError` (notify . ERR)
deleteRcvFiles `catchError` (notify . RFERR)
deleteRcvFilesTmpPaths `catchError` (notify . RFERR)
threadDelay int
where
deleteConns =
withLock (deleteLock c) "cleanupManager" $ do
void $ withStore' c getDeletedConnIds >>= deleteDeletedConns c
withStore' c deleteUsersWithoutConns >>= mapM_ notifyUserDeleted
notifyUserDeleted userId = atomically $ writeTBQueue (subQ c) ("", "", APC SAENone $ DEL_USER userId)
deleteFiles = do
-- cleanup rcv files marked for deletion
withStore' c deleteUsersWithoutConns >>= mapM_ (notify . DEL_USER)
deleteRcvFiles = do
rcvDeleted <- withStore' c getCleanupRcvFilesDeleted
forM_ rcvDeleted $ \(fId, p) -> do
forM_ rcvDeleted $ \(fId, p) -> flip catchError (notify . RFERR) $ do
removePath =<< toFSFilePath p
withStore' c (`deleteRcvFile'` fId)
-- cleanup rcv tmp paths
deleteRcvFilesTmpPaths = do
rcvTmpPaths <- withStore' c getCleanupRcvFilesTmpPaths
forM_ rcvTmpPaths $ \(fId, p) -> do
forM_ rcvTmpPaths $ \(fId, p) -> flip catchError (notify . RFERR) $ do
removePath =<< toFSFilePath p
withStore' c (`updateRcvFileNoTmpPath` fId)
notify :: forall e. AEntityI e => ACommand 'Agent e -> ExceptT AgentErrorType m ()
notify cmd = atomically $ writeTBQueue subQ ("", "", APC (sAEntity @e) cmd)

processSMPTransmission :: forall m. AgentMonad m => AgentClient -> ServerTransmission BrokerMsg -> m ()
processSMPTransmission c@AgentClient {smpClients, subQ} (tSess@(_, srv, _), v, sessId, rId, cmd) = do
Expand Down