Runtime crashes on parallel execution, GHC 7.0.4-7.4.1
Code gets runtime crashes if executed on multiple parallel threads with Control.Monad.Parallel.mapM
- if the whole data is passed as one chunk to the mapM
, then crashes are avoided.
The crashes are repeatable (same code with the same data crashes 90% of time), but with different crash messages and place/time of crash. For example:
"LNB_transform_source: internal error: stg_ap_p_ret
(GHC version 7.0.4 for x86_64_apple_darwin)
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
Abort trap: 6"
Another: "Bus error: 10"
Another, after successfully finishing execution
"LNB_transform_source(22223,0x7fff7e200960) malloc: *** error for object 0x2c: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6"
Another: "Segmentation fault: 11"
I cannot isolate a minimalistic test case easily; the program is quite tricky and didn't crash when was simpler; however, the problems appeared around the same time as when xml parsing was switched from Text.XML.HXT.Core to Text.XML.Expat.SAX library, but there was a load of other changes at the same time.
very rough code logic:
Control.Monad.Parallel.mapM processfiles [[filenames]]
Parallel.processfiles = do
outsideapphandles <- runInteractiveCommand "outsideapp"
mapM (processfile handles) [filenames]
processfile = do
file <- readfile filename
tokens <- SAX.parse file
outputtokens <- map (processtoken outsideapphandles) tokens
writefile outputtokens
processtoken = unsafeperformIO $ do
hPutStrLn inputhandle token
return hgetLine outputhandle