liquidhaskell
liquidhaskell copied to clipboard
Liquid GHC plugin segfaults and/or `free`s a `malloc`ed pointer twice when building in parallel
This one is very mysterious to me, because I don't have much idea where to start looking, and because I thought I wouldn't have to deal with these kind of errors when I switched from C to Haskell!
With ghc-options: -j
set in the tests.cabal
file across the board, some test groups will often fail with cabal complaining GHC double free'd or segfaulted. For this reason, I cannot build the tests in parallel, and I fear this will bite users who are used to building their modules in parallel if they try to integrate the plugin to their workflow.
Some ideas:
Maybe it's in the FFI somewhere with Z3 interactions?
Maybe it's caused by an unsafePerformIO
somewhere? I know there is at least one in the plugin for an IORef...
Intrepid exploration is required!
Wow!!! Unlikely to be z3 we don’t use the FFI for that - just talk to z3 via processes/pipes!
On Fri, Apr 29, 2022 at 7:11 AM Matt Walker @.***> wrote:
This one is very mysterious to me, because I don't have much idea where to start looking, and because I thought I wouldn't have to deal with these kind of errors when I switched from C to Haskell!
With ghc-options: -j set in the tests.cabal file across the board, some test groups will often fail with cabal complaining GHC double free'd or segfaulted. For this reason, I cannot build the tests in parallel, and I fear this will bite users who are used to building their modules in parallel if they try to integrate the plugin to their workflow.
Some ideas:
Maybe it's in the FFI somewhere with Z3 interactions?
Maybe it's caused by an unsafePerformIO somewhere? I know there is at least one in the plugin for an IORef...
Intrepid exploration is required!
— Reply to this email directly, view it on GitHub https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_ucsd-2Dprogsys_liquidhaskell_issues_1978&d=DwMCaQ&c=-35OiAkTchMrZOngvJPOeA&r=r3JfTqNkpwIJ1InE9-ChC2ld7xwATxgUx5XHAdA0UnA&m=A3f-HVs_mJojebCHi18lx5t-WGqQDgCHcPE3vwTJq9gKj_9QHSopzJjb972jYW2I&s=Aju6GSEI33LLc-Ww3e25lAhvXrqNN-Iib6kCBpWth2E&e=, or unsubscribe https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AAMS4OFYRYNGEWXEY5TMHBDVHPUZ3ANCNFSM5UWEWROA&d=DwMCaQ&c=-35OiAkTchMrZOngvJPOeA&r=r3JfTqNkpwIJ1InE9-ChC2ld7xwATxgUx5XHAdA0UnA&m=A3f-HVs_mJojebCHi18lx5t-WGqQDgCHcPE3vwTJq9gKj_9QHSopzJjb972jYW2I&s=UFTZ2mSMkLJyDv6bzs2MzdCWRUp_-28QtfR8XgbDLN4&e= . You are receiving this because you are subscribed to this thread.Message ID: @.***>
I think it has to do with the IORef
that has been unsafePerformIO
d that holds the global config, or cmdargs
itself. When processing the config using
processPragmas :: Config -> [Located String] -> IO Config
processPragmas c pragmas = withArgs (val <$> pragmas) $ cmdArgsRun config { modeValue = (modeValue config) { cmdArgsValue = c } }
instead of foldM withPragma c ps
in https://github.com/ucsd-progsys/liquidhaskell/blob/594be9a9f6208dc9ef017466fda035451bb38354/src/Language/Haskell/Liquid/UX/CmdLine.hs#L625-L626
more things crash that didn't crash before. Maybe cmdargs
's verbosity settings aren't thread safe? This is where we set them for the current module.
I tried removing those lines and it still crashes, so I guess not?
I think I figured this one. In order to discover it, I created a global lock to sequentialise execution of the plugin when GHC built multiple modules concurrently. Then I started shrinking the scope in which the lock was acquired until builds started segfaulting. This pointed rather quickly at withArgs [s] $ cmdArgsRun ...
which is mutating global state.
Wow, that’s amazing Facundo! Thank you for cracking this!!!
On Mon, Jun 26, 2023 at 7:12 AM Facundo Domínguez @.***> wrote:
I think I figured this one. In order to discover it, a created a global lock to sequentialise execution of the plugin when GHC built multiple modules concurrently. Then I started shrinking the scope in which the lock was acquired until builds started segfaulting. This pointed rather quickly at withArgs [s] $ cmdArgsRun ... which is mutating global state.
— Reply to this email directly, view it on GitHub https://urldefense.com/v3/__https://github.com/ucsd-progsys/liquidhaskell/issues/1978*issuecomment-1607581494__;Iw!!Mih3wA!FEW4FWWhTFYi29attMM1krLjFteh8S-_QCx2UHzlXwbDNlNsOtSUX-GAZJHyh5dZRP8yFEv1EZfoSgtkt9S-TQIo$, or unsubscribe https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AAMS4OGUEL6UAWPP6WO25JDXNGKFBANCNFSM5UWEWROA__;!!Mih3wA!FEW4FWWhTFYi29attMM1krLjFteh8S-_QCx2UHzlXwbDNlNsOtSUX-GAZJHyh5dZRP8yFEv1EZfoSgtkt3Hht2Yr$ . You are receiving this because you commented.Message ID: @.***>
--
- Ranjit.