Skip to content

Commit

Permalink
fix: mitigate sydtest crash when used recursively
Browse files Browse the repository at this point in the history
This closes NorfairKing#91 by avoiding
a call to `withArgs` if the argument list is already empty.

`withArgs` can crash in a concurrent environment (see GHC BUG
https://gitlab.haskell.org/ghc/ghc/-/issues/18261), hence we reduce the
chance of this happening by not calling it when the list of arguments is
already in the required state (e.g. empty).
  • Loading branch information
guibou committed Sep 22, 2024
1 parent 4e317b3 commit 9b27d16
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion sydtest/src/Test/Syd/Runner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,22 @@ import Text.Printf
-- it removes all the arguments initially provided to sydtest and provides a
-- reproducible environment.
setNullArgs :: IO a -> IO a
setNullArgs action = withArgs [] action
setNullArgs action = do
-- Check that args are not empty before setting it to empty.
-- This is a workaround for https://gitlab.haskell.org/ghc/ghc/-/issues/18261
-- In summary, `withArgs` is not thread-safe, hence we would like to avoid it
-- as much as possible.
--
-- If sydtest is used in a more complex environment which may use `withArgs`
-- too, we would like to avoid a complete crash of the program.
--
-- Especially, if sydtest is used itself in a sydtest test (e.g. in order to
-- test sydtest command line itself), it may crash, see
-- https://github.com/NorfairKing/sydtest/issues/91 for details.
args <- getArgs
if null args
then action
else withArgs [] action

sydTestResult :: Settings -> TestDefM '[] () r -> IO (Timed ResultForest)
sydTestResult settings spec = do
Expand Down

0 comments on commit 9b27d16

Please sign in to comment.