Skip to content

incorrect handling of StackOverflow exception in the event manager

Under high pressure of registerTimeouts the event manager thread's stack overflows.

Testcases: Shachaf initially reported this testcase on #ghc, which is irreproducible locally:

import Control.Monad;
import Control.Concurrent
main = replicateM_ 1000000 (forkIO (threadDelay 1))

to be compiled and run as follows:

$ ghc -O2 -threaded Main.hs && time ./Main +RTS -N

Limiting the stack to the minimum helped to reproduce this locally, both on x86 and x64:

import Control.Monad
import Control.Concurrent
main = replicateM_ 502 (forkIO (threadDelay 1)) -- 504 on x64
$ ghc -O2 -threaded -with-rtsopts="-N8 -K4" rplfrk.hs && ./rplfrk # -K8 on x64

and this, though less deterministically:

import Control.Monad
import Control.Concurrent
main = replicateM_ 340 ( forkIO (threadDelay 1))
$ ghc -O2 -threaded -rtsopts repl2-x86.hs && ./repl2-x86 +RTS -N1 -K4

Error messages look like:

Stack space overflow: current size 4 bytes.
Use `+RTS -Ksize -RTS' to increase it.
repl2-x86: sendWakeup: invalid argument (Bad file descriptor)
[...repeated...]
repl2-x86: ioManagerDie: write: Bad file descriptor
Trac metadata
Trac field Value
Version 7.7
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/base
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information