Skip to content

Commit

Permalink
RTS workaround converting SIGTERM into SIGINT
Browse files Browse the repository at this point in the history
This is important for graceful shutdown, cleaning up resources in
`bracket` statements.

Fixes #1697
  • Loading branch information
DavidEichmann committed Feb 24, 2022
1 parent 84ea079 commit fcba44c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cardano-node/src/Cardano/Node/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import System.Directory (canonicalizePath, createDirectoryIfMissing, m
import System.Environment (lookupEnv)

#ifdef UNIX
import GHC.Weak (deRefWeak)
import System.Posix.Files
import qualified System.Posix.Signals as Signals
import System.Posix.Types (FileMode)
Expand Down Expand Up @@ -105,6 +106,23 @@ runNode
:: PartialNodeConfiguration
-> IO ()
runNode cmdPc = do
-- Workaround to ensure that the main thread throws an async exception on
-- receiving a SIGTERM signal.
#ifdef UNIX
-- Similar implementation to the RTS's handling of SIGINT (see GHC's
-- TopHandler.hs)
runThreadIdWk <- mkWeakThreadId =<< myThreadId
void $ Signals.installHandler
Signals.sigTERM
(Signals.CatchOnce $ do
runThreadIdMay <- deRefWeak runThreadIdWk
case runThreadIdMay of
Nothing -> return ()
Just runThreadId -> killThread runThreadId
)
Nothing
#endif

-- TODO: Remove sodiumInit: https://github.com/input-output-hk/cardano-base/issues/175
Crypto.sodiumInit

Expand Down

0 comments on commit fcba44c

Please sign in to comment.