Skip to content

Memory leak under GHC 8.8.x

Summary

The following program that uses Streamly, leaks memory under GHC 8.8.x. It doesn't leak memory under 8.6 and 8.10 alpha2.

import Data.Function ((&))

import Streamly
import qualified Streamly.Memory.Array as A
import qualified Streamly.Prelude as S
import qualified Streamly.Internal.Network.Socket as SK
import qualified Streamly.Internal.Network.Inet.TCP as TCP

main =
      S.unfold TCP.acceptOnPort 8090 -- SerialT IO Socket
    & S.concatMapWith async frames  -- SerialT IO (Array Word8)
    & S.drain

    where

    frames sk =
          S.unfold SK.read sk
        & S.chunksOf 1 (A.writeN 1)
  • With GHC 8.8.x the program keeps on consuming memory until it crashes.
  • With GHC 8.6.x the program runs under constant memory.
  • With GHC 8.10 alpha2 it doesn't looks like the program is leaking memory (at least not as fast as 8.8.x)

Steps to reproduce

Clone the repo from from github https://github.com/composewell/streamly, Checkout the crasher branch and run the Crasher.hs program in the examples directory

git clone https://github.com/composewell/streamly
cd streamly
git checkout crasher
$ cd examples/
$ ghc -O2 Crasher.hs -threaded
$ ./Crasher +RTS -N -s -RTS

The program should start listening on port 8090, send input to the program

$ cat /dev/zero | nc 127.0.0.1 8090

Repeat with different GHC version and monitor the memory usage.

Expected behavior

Memory usage should be constant under GHC 8.8.x as well

Environment

  • GHC version used: 8.6.3, 8.8.1, 8.10 alpha2

Optional:

  • Operating System: MacOS 10.15

We need to figure whether it's a bug in the Streamly code or it's a GHC issue.

Edited by Andreas Klebinger
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information