Skip to content

Commit

Permalink
Add SIGTERM handler
Browse files Browse the repository at this point in the history
  • Loading branch information
goodlyrottenapple committed Mar 25, 2024
1 parent 99a39cb commit bc7c1b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ executables:
- stm
- text
- transformers
- unix
ghc-options:
- -rtsopts
- -threaded
Expand Down
22 changes: 22 additions & 0 deletions tools/booster/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ import Booster.SMT.Interface (SMTOptions (..))
import Booster.Syntax.ParsedKore (loadDefinition)
import Booster.Trace
import Booster.Util qualified as Booster
import Control.Concurrent (killThread, mkWeakThreadId, myThreadId)
import Data.Limit (Limit (..))
import GHC.Weak (deRefWeak)
import GlobalMain qualified
import Kore.Attribute.Symbol (StepperAttributes)
import Kore.BugReport (BugReportOption (..), withBugReport)
Expand Down Expand Up @@ -83,9 +85,29 @@ import Proxy (KoreServer (..), ProxyConfig (..))
import Proxy qualified
import SMT qualified as KoreSMT
import Stats qualified
import System.Posix.Signals qualified as Signals

{- | Workaround to ensure that the main thread throws an async exception on
receiving a SIGTERM signal.
based on https://github.com/IntersectMBO/cardano-node/pull/3641/files
-}
installSigTermHandler :: IO ()
installSigTermHandler = do
-- Similar implementation to the RTS's handling of SIGINT (see GHC's
-- https://gitlab.haskell.org/ghc/ghc/-/blob/master/libraries/base/GHC/TopHandler.hs).
runThreadIdWk <- mkWeakThreadId =<< myThreadId
void $
Signals.installHandler
Signals.sigTERM
( Signals.CatchOnce $ do
runThreadIdMay <- deRefWeak runThreadIdWk
forM_ runThreadIdMay killThread
)
Nothing

main :: IO ()
main = do
installSigTermHandler
startTime <- getTime Monotonic
options <- execParser clParser
let CLProxyOptions
Expand Down

0 comments on commit bc7c1b0

Please sign in to comment.