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

Multiples sydTest segfault in parallel #91

Open
guibou opened this issue Aug 14, 2024 · 1 comment
Open

Multiples sydTest segfault in parallel #91

guibou opened this issue Aug 14, 2024 · 1 comment

Comments

@guibou
Copy link
Contributor

guibou commented Aug 14, 2024

sydTest (and most related functions, such as sydTestResults, ...) cannot be run twice in a concurrent environment because they internally relies on non thread safe features.

Especially (but maybe not exhaustive):

Since this library is built on top of the curses interface, it is not thread-safe.

The following code will hence hapilly segfault:

import Test.Syd

main = sydTest $ do
  it "test 1" $ do
    sydTest $ it "inner" $ 1 `shouldBe` 1
  it "test 2" $ do
    sydTest $ it "inner" $ 1 `shouldBe` 1

Built with -O2 -threaded and run with --continuous +RTS -N and you'll eventually get a segfault.

This is not a problem in traditionnal uses of sydtest, however, it is a problem when using sydtest in the sydtest test suite itself. That's what I tried when working on #80 (especially, see comment #80 (comment)).

Note that a workaround is to use "internal" functions which does not do the detection, such as:

  specForest <- execTestDefM defaultSettings spec
  resultForest <- runSpecForestAsynchronously defaultSettings 8 specForest

I wanted to track in a ticket that sydTest cannot be run concurrently, so if someone hit a segmentation fault, maybe they'll find this ticket. I'm unsure sydtest should be fixed (e.g. the fix would be highly invasive and complex), however maybe the documentation may list the "unsafe" functions.

@guibou guibou changed the title Multiples sydTest cannot be called in parallel Multiples sydTest segfault in parallel Aug 14, 2024
@NorfairKing
Copy link
Owner

Huh, I didn't expect a segfault.
I thought one of them would fail while the other passed or so. Thanks for pointing this out!

guibou added a commit to guibou/sydtest that referenced this issue Sep 22, 2024
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).
@guibou guibou mentioned this issue Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants