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

Add SIGTERM handler #560

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
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