Spurious program crashes

I'm getting crashes like this and I cannot figure out what the problem is. I'm launching a bunch of threads that connect to a server via TCP and exchange packets. I am running operations like connect and receive in a timeout function that launches two threads and uses an MVar to figure out who's done first. The timeout function then kills the two threads. Any ideas what could be causing this? I feel like a Haskell guinea pig these days :-). My Cabal build options look like this ghc-options: -fglasgow-exts -Wall -O -debug And the stack trace: Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: 0x3139322e 0x0027c174 in s8j1_info () (gdb) where #0 0x0027c174 in s8j1_info () #1 0x0021c9f4 in StgRunIsImplementedInAssembler () at StgCRun.c:576 #2 0x0021cdc4 in schedule (mainThread=0x1100360, initialCapability=0x308548) at Schedule.c:932 #3 0x0021dd6c in waitThread_ (m=0x1100360, initialCapability=0x0) at Schedule.c:2156 #4 0x0021dc50 in scheduleWaitThread (tso=0x13c0000, ret=0x0, initialCapability=0x0) at Schedule.c:2050 #5 0x00219548 in rts_evalLazyIO (p=0x29b47c, ret=0x0) at RtsAPI.c:459 #6 0x001e4768 in main (argc=2262116, argv=0x308548) at Main.c:104 Thanks, Joel -- http://wagerlabs.com/

On Wed, Nov 16, 2005 at 05:37:34PM +0000, Joel Reymont wrote:
I'm getting crashes like this and I cannot figure out what the problem is. I'm launching a bunch of threads that connect to a server via TCP and exchange packets.
I am running operations like connect and receive in a timeout function that launches two threads and uses an MVar to figure out who's done first. The timeout function then kills the two threads.
Any ideas what could be causing this?
Let me guess - excessive use of unsafe operations (like unsafe*, FFI)? I've got an impression that you use them too often for a fresh Haskell programmer. Too often for a Haskell programmer in general. Excuse me if I wrong. Best regards Tomasz

I really don't use more FFI than needed to send and receive binary packets over the network. I don't even use FPS these days and all the allocaBytes code checks for nullPtr. My hunch is that this is to do with killing threads that perform FFI in my timeout code. It would kill blocking connect and hGet operations for example. timeout :: forall a.Show a => Int -> IO a -> IO a timeout secs fun = do mvar <- newEmptyMVar tid1 <- forkIO $ do result <- try fun putMVar mvar $ either (Left . show) (Right . id) result tid2 <- forkIO $ do threadDelay (secs * 1000000) putMVar mvar (Left "timeout") maybeResult <- takeMVar mvar forkIO $ do killThread tid1 killThread tid2 case maybeResult of Right a -> return a Left b -> fail b On Nov 16, 2005, at 5:52 PM, Tomasz Zielonka wrote:
Let me guess - excessive use of unsafe operations (like unsafe*, FFI)? I've got an impression that you use them too often for a fresh Haskell programmer. Too often for a Haskell programmer in general.

On Wed, Nov 16, 2005 at 06:16:48PM +0000, Joel Reymont wrote:
I really don't use more FFI than needed to send and receive binary packets over the network. I don't even use FPS these days and all the allocaBytes code checks for nullPtr.
Then please accept my apologies. I may have confused you with someone else. Best regards Tomasz
participants (2)
-
Joel Reymont
-
Tomasz Zielonka