[GHC] #11508: QuickCheck application hangs with concurrent read/write of Chan

#11508: QuickCheck application hangs with concurrent read/write of Chan -------------------------------------+------------------------------------- Reporter: orion | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Keywords: | Operating System: FreeBSD Architecture: x86_64 | Type of failure: None/Unknown (amd64) | Test Case: | Blocked By: https://github.com/centromere | /ghc-bug-testcase | Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- If you configure the test case like so: {{{ $ cabal configure --enable-tests -fbad }}} The QuickCheck application will hang when executed: {{{ $ ./dist/build/properties/properties --quickcheck-verbose --quickcheck- tests 10 10 9 8 7 6 5 4 3 2 1 10 testCase 1 a: }}} If you compile it without the 'bad' flag, it will execute successfully. The problem is reproducible on both FreeBSD 10 and Ubuntu 15.10. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11508 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11508: QuickCheck application hangs with concurrent read/write of Chan -------------------------------------+------------------------------------- Reporter: orion | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: FreeBSD | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: | https://github.com/centromere/ghc- | bug-testcase Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by orion): * Attachment "truss_output.txt" added. Truss output from bad application -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11508 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11508: QuickCheck application hangs with concurrent read/write of Chan -------------------------------------+------------------------------------- Reporter: orion | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: FreeBSD | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: | https://github.com/centromere/ghc- | bug-testcase Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by orion: @@ -29,1 +29,3 @@ - The problem is reproducible on both FreeBSD 10 and Ubuntu 15.10. + The problem is reproducible on both FreeBSD 10 and Ubuntu 15.10. Attached + is the output from truss when run against the bad version of the + application. New description: If you configure the test case like so: {{{ $ cabal configure --enable-tests -fbad }}} The QuickCheck application will hang when executed: {{{ $ ./dist/build/properties/properties --quickcheck-verbose --quickcheck- tests 10 10 9 8 7 6 5 4 3 2 1 10 testCase 1 a: }}} If you compile it without the 'bad' flag, it will execute successfully. The problem is reproducible on both FreeBSD 10 and Ubuntu 15.10. Attached is the output from truss when run against the bad version of the application. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11508#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11508: QuickCheck application hangs with concurrent read/write of Chan -------------------------------------+------------------------------------- Reporter: orion | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: | https://github.com/centromere/ghc- | bug-testcase Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by pgj): * os: FreeBSD => Unknown/Multiple Comment: Based on the description in the ticket, I believe it is not platform- specific, so I am updating the respective field. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11508#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11508: QuickCheck application hangs with concurrent read/write of Chan -------------------------------------+------------------------------------- Reporter: orion | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * testcase: https://github.com/centromere/ghc-bug-testcase => @@ -1,1 +1,2 @@ - If you configure the test case like so: + If you configure the test case in https://github.com/centromere/ghc-bug- + testcase like so: New description: If you configure the test case in https://github.com/centromere/ghc-bug- testcase like so: {{{ $ cabal configure --enable-tests -fbad }}} The QuickCheck application will hang when executed: {{{ $ ./dist/build/properties/properties --quickcheck-verbose --quickcheck- tests 10 10 9 8 7 6 5 4 3 2 1 10 testCase 1 a: }}} If you compile it without the 'bad' flag, it will execute successfully. The problem is reproducible on both FreeBSD 10 and Ubuntu 15.10. Attached is the output from truss when run against the bad version of the application. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11508#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11508: QuickCheck application hangs with concurrent read/write of Chan -------------------------------------+------------------------------------- Reporter: orion | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): I haven't looked carefully at the ticket but if it helps to compile with `-fno-omit-yields` then you are being bitten by #367. See that ticket and the [http://downloads.haskell.org/~ghc/master/users-guide//bugs.html#bugs- in-ghc|Users Guide] for details. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11508#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11508: QuickCheck application hangs with concurrent read/write of Chan -------------------------------------+------------------------------------- Reporter: orion | Owner: Type: bug | Status: infoneeded Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => infoneeded -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11508#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11508: QuickCheck application hangs with concurrent read/write of Chan -------------------------------------+------------------------------------- Reporter: orion | Owner: Type: bug | Status: infoneeded Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): I had a quick look at the testcase. Judging from the eventlog it appears that there are a few threads blocking: * one thread blocking on a `MVar` * another blocking on an STM retry Finally, we also have foreign calls involved due to the `ByteString` usage. Sadly `-fno-omit-yields` doesn't seem to help. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11508#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11508: QuickCheck application hangs with concurrent read/write of Chan -------------------------------------+------------------------------------- Reporter: orion | Owner: Type: bug | Status: infoneeded Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by orion): The status of this ticket is, "infoneeded". What information do you need? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11508#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11508: QuickCheck application hangs with concurrent read/write of Chan -------------------------------------+------------------------------------- Reporter: orion | Owner: Type: bug | Status: infoneeded Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by erikd): I just tried this on x86_64 Debian with ghc-7.10.3 (installed from Debian) and it seems to run fine. At the end I get {{{ 2 1 1 OK (10.16s) +++ OK, passed 100 tests. All 2 tests passed (20.32s) }}} Tried three runs without a single hang. Debian applies a couple of patches to the official GHC 7.10.3 tarball. Those patches are in the file http://ftp.debian- ports.org/debian/pool/main/g/ghc/ghc_7.10.3-7.debian.tar.xz . I've had a brief look at those patches, but none of them seem relevant to this issue. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11508#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11508: QuickCheck application hangs with concurrent read/write of Chan -------------------------------------+------------------------------------- Reporter: orion | Owner: Type: bug | Status: infoneeded Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by orion): I just reproduced this on FreeBSD. What follows is the output from cabal freeze --enable-tests: {{{ constraints: QuickCheck ==2.8.2, ansi-terminal ==0.6.2.3, ansi-wl-pprint ==0.6.7.3, array ==0.5.1.0, async ==2.1.0, base ==4.8.2.0, binary ==0.7.5.0, bytestring ==0.10.6.0, clock ==0.6.0.1, containers ==0.5.6.2, deepseq ==1.4.1.1, directory ==1.2.2.0, filepath ==1.4.0.0, ghc-prim ==0.4.0.0, integer-gmp ==1.0.0.0, mtl ==2.2.1, optparse-applicative ==0.12.1.0, parsec ==3.1.9, pretty ==1.1.2.0, primitive ==0.6.1.0, process ==1.2.3.0, random ==1.1, regex-base ==0.93.2, regex-tdfa-rc ==1.1.8.3, rts ==1.0, stm ==2.4.4.1, tagged ==0.8.3, tasty ==0.11.0.2, tasty-quickcheck ==0.8.4, template-haskell ==2.10.0.0, text ==1.2.2.1, tf-random ==0.5, time ==1.5.0.1, transformers ==0.4.2.0, transformers-compat ==0.5.1.4, unbounded-delays ==0.1.0.9, unix ==2.7.1.0 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11508#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11508: QuickCheck application hangs with concurrent read/write of Chan -------------------------------------+------------------------------------- Reporter: orion | Owner: Type: bug | Status: infoneeded Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by erikd): Even with the cabal.config file provided by @orion it still doesn't hang on my system. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11508#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11508: QuickCheck application hangs with concurrent read/write of Chan -------------------------------------+------------------------------------- Reporter: orion | Owner: Type: bug | Status: infoneeded Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by erikd): My first try at reproducing this hang failed because I didn't read the ticket. The secret is configuring with `-fbad` as follows: {{{ $ cabal configure --enable-tests -fbad }}} With that I got the hang reported by @orion. I then added `-threaded` to the cabal files `ghc-options` line for the `properties` target and now it no longer hangs. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11508#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11508: QuickCheck application hangs with concurrent read/write of Chan -------------------------------------+------------------------------------- Reporter: orion | Owner: Type: bug | Status: infoneeded Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by erikd): @bgamari Is this really a bug? To me (possibly because I've hit this problem before) its not too surprising that use of `MVar`s and `STM` requires use of the threaded RTS. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11508#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11508: QuickCheck application hangs with concurrent read/write of Chan -------------------------------------+------------------------------------- Reporter: orion | Owner: Type: bug | Status: infoneeded Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by erikd): If I change the program so that it no longer runs the tests via QuickCheck as follows: {{{ {-# LANGUAGE OverloadedStrings, CPP #-} module Main where import Imports import Control.Concurrent import Control.Concurrent.Async import Data.ByteString instance Arbitrary ByteString where arbitrary = pack <$> arbitrary doFoo :: Bool -> Int -> ByteString -> (ByteString -> IO ()) -> (IO ByteString) -> IO ByteString doFoo _ 0 g _ _ = return g doFoo b i g w r = if b then do w g doFoo False (i-1) g w r else do f <- r doFoo True (i-1) f w r prop :: ByteString -> IO Bool prop x = do chan <- newChan let w s = writeChan chan s r = readChan chan (y, z) <- concurrently (doFoo True 10 x w r) (doFoo False 10 x w r) return $ y == z main :: IO () main = print =<< prop "Hello" }}} then when the program runs it terminates with: {{{ properties: thread blocked indefinitely in an MVar operation }}} Interestingly, it does that regardless of whether the program is compiled with `-threaded` or not. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11508#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11508: QuickCheck application hangs with concurrent read/write of Chan -------------------------------------+------------------------------------- Reporter: orion | Owner: Type: bug | Status: infoneeded Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by erikd): Went away and did something else and then it occured to me that QuickCheck must be silently swallowing the "blocked MVar" exception. Looking at the code for `readChan` and `writeChan` from `Control.Concurrent.Chan` we can see that they are implemented with `MVars`. Interestingly, the docs for `Control.Concurrent.MVar` do warn about "race conditions, deadlocks or uncaught exceptions", but the docs for `Control.Concurrent.Chan` do not reflect this, and neither do they mention the `STM` implementation of channels in `Control.Concurrent.STM.TChan` which are far more robust than the `MVar` version. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11508#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11508: QuickCheck application hangs with concurrent read/write of Chan -------------------------------------+------------------------------------- Reporter: orion | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: x86_64 | (amd64) Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by erikd): * status: infoneeded => closed * resolution: => fixed Comment: The documentation for `Control.Concurrent.Chan` in the GHC git tree has been updated to include a warning that `Chan` inherits all the caveats of `MVar`s and suggests the use of `TChan` from the `stm` library instead. Closing this as "wontfix" but the "fix" is to use `TChan` instead of `Chan`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11508#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC