File tree Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -2112,8 +2112,7 @@ cleanupManager c@AgentClient {subQ} = do
21122112 liftIO $ threadDelay' delay
21132113 int <- asks (cleanupInterval . config)
21142114 ttl <- asks $ storedMsgDataTTL . config
2115- forever $ do
2116- liftIO $ waitUntilActive c
2115+ forever $ waitActive $ do
21172116 run ERR deleteConns
21182117 run ERR $ withStore' c (`deleteRcvMsgHashesExpired` ttl)
21192118 run ERR $ withStore' c (`deleteSndMsgsExpired` ttl)
@@ -2133,6 +2132,7 @@ cleanupManager c@AgentClient {subQ} = do
21332132 step <- asks $ cleanupStepInterval . config
21342133 liftIO $ threadDelay step
21352134 -- we are catching it to avoid CRITICAL errors in tests when this is the only remaining handle to active
2135+ waitActive :: ReaderT Env IO a -> AM' ()
21362136 waitActive a = liftIO (E. tryAny $ waitUntilActive c) >>= either (\ _ -> pure () ) (\ _ -> void a)
21372137 deleteConns =
21382138 withLock (deleteLock c) " cleanupManager" $ do
Original file line number Diff line number Diff line change @@ -372,21 +372,23 @@ getAgentWorker' toW fromW name hasWork c key ws work = do
372372 restart <- atomically $ getWorker >>= maybe (pure False ) (shouldRestart e_ (toW w) t maxRestarts)
373373 when restart runWork
374374 shouldRestart e_ Worker {workerId = wId, doWork, action, restarts} t maxRestarts w'
375- | wId == workerId (toW w') =
376- checkRestarts . updateRestartCount t =<< readTVar restarts
375+ | wId == workerId (toW w') = do
376+ rc <- readTVar restarts
377+ isActive <- readTVar $ active c
378+ checkRestarts isActive $ updateRestartCount t rc
377379 | otherwise =
378380 pure False -- there is a new worker in the map, no action
379381 where
380- checkRestarts rc
381- | restartCount rc < maxRestarts = do
382+ checkRestarts isActive rc
383+ | isActive && restartCount rc < maxRestarts = do
382384 writeTVar restarts rc
383385 hasWorkToDo' doWork
384386 void $ tryPutTMVar action Nothing
385387 notifyErr INTERNAL
386388 pure True
387389 | otherwise = do
388390 TM. delete key ws
389- notifyErr $ CRITICAL True
391+ when isActive $ notifyErr $ CRITICAL True
390392 pure False
391393 where
392394 notifyErr err = do
You can’t perform that action at this time.
0 commit comments