Skip to content

Ghci does not terminate cleanly after Stack Overflow Error

Summary

In certain cases, after a Stack Overflow occurs, Ghci threads are not correctly cleaned up, letting them linger with 100% CPU usage.

Steps to reproduce

Content of Err.hs:

data X a = X
instance Show a => Show (X a) where
x = show (X :: X Int)

Invoke:

> ghci Err.hs +RTS -M2G -K100M -RTS -e "x"
Err.hs:2:10-29: warning: [-Wmissing-methods]
    • No explicit implementation for
        either ‘showsPrec’ or ‘show’
    • In the instance declaration for ‘Show (X a)
  |
2 | instance Show a => Show (X a) where
  |          ^^^^^^^^^^^^^^^^^^^^
<interactive>: stack overflow

However, this computation does not terminate and you can verify in top or htop that there is at least one ghc thread with 100% CPU usage.

Note, that you can get the desired behaviour, if you omit the typeclass constraint on a in the Instance declaration. (Assume file Ok.hs)

data X a = X
instance Show (X a) where
x = show (X :: X Int)

Now the invocation ghci Ok.hs +RTS -M2G -K100M -RTS -e "x" terminates with a Stack Overflow correctly.

Moreover, reducing the amount of stack (e.g. to -K1M) also solves the issue.

Expected behavior

Eventually terminate with a stack overflow.

What do you expect the reproducer described above to do?

It will not terminate and also not react on ctrl+c or other signals. You have to send sigkill to it.

Environment

  • GHC version used: 8.8.4

Optional:

  • Operating System: NixOS
  • System Architecture: x86_64
Edited by Hannes Siebenhandl
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information