Skip to content

Commit bbcb1ab

Browse files
authored
agent: treat blocked STM and other critical errors that offer restart as temporary (#1405)
1 parent a64c1aa commit bbcb1ab

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/Simplex/Messaging/Agent/Client.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,7 @@ temporaryAgentError = \case
13881388
PROXY _ _ (ProxyProtocolError (SMP.PROXY (SMP.BROKER e))) -> tempBrokerError e
13891389
PROXY _ _ (ProxyProtocolError (SMP.PROXY SMP.NO_SESSION)) -> True
13901390
INACTIVE -> True
1391+
CRITICAL True _ -> True -- critical errors that do not show restart button are likely to be permanent
13911392
_ -> False
13921393
where
13931394
tempBrokerError = \case

src/Simplex/Messaging/Agent/Env/SQLite.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module Simplex.Messaging.Agent.Env.SQLite
4242
where
4343

4444
import Control.Concurrent (ThreadId)
45+
import Control.Exception (BlockedIndefinitelyOnSTM (..), SomeException, fromException)
4546
import Control.Monad.Except
4647
import Control.Monad.IO.Unlift
4748
import Control.Monad.Reader
@@ -78,7 +79,6 @@ import Simplex.Messaging.Transport (SMPVersion)
7879
import Simplex.Messaging.Util (allFinally, catchAllErrors, catchAllErrors', tryAllErrors, tryAllErrors')
7980
import System.Mem.Weak (Weak)
8081
import System.Random (StdGen, newStdGen)
81-
import UnliftIO (SomeException)
8282
import UnliftIO.STM
8383

8484
type AM' a = ReaderT Env IO a
@@ -313,7 +313,9 @@ agentFinally = allFinally mkInternal
313313
{-# INLINE agentFinally #-}
314314

315315
mkInternal :: SomeException -> AgentErrorType
316-
mkInternal = INTERNAL . show
316+
mkInternal e = case fromException e of
317+
Just BlockedIndefinitelyOnSTM -> CRITICAL True "Thread blocked indefinitely in STM transaction"
318+
_ -> INTERNAL $ show e
317319
{-# INLINE mkInternal #-}
318320

319321
data Worker = Worker

0 commit comments

Comments
 (0)