typelevel / typelevel/fs2

Memory leak when using WriterT

Open
#2,908 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Scala
Stars
2.5k
Forks
636
Avg merge
2d 4h
Merged PRs (30d)
7

Description

I'm experiencing a memory leak on the latest v3.2.7 when using an effect type that includes WriterT. I've put together a repository to reproduce the issue and to demonstrate that it doesn't happen when using plain IO -- https://github.com/mrdziuban/fs2-WriterT-memory

Here's a minimized example to reproduce the issue:

import cats.data.WriterT
import cats.effect.IO
import cats.effect.unsafe.implicits.global
import fs2.Stream

val longString = "a" * (1024 * 1024)

Stream[WriterT[IO, Unit, *], Unit](()).repeat.map(_ => longString).compile.drain.run.unsafeRunSync()

Also in a scastie here: https://scastie.scala-lang.org/mrdziuban/o8jjvkgOQVOwYnJ1A831dQ/4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimized Scala example in the issue and compare its WriterT behavior with plain IO, then inspect the linked reproduction repository and Scastie example. Done means the repeating stream no longer retains the large mapped strings or exhibits the reported memory leak when run with WriterT.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
stream-processing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.