Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in Signal#discrete #799

Closed
mpilquist opened this issue Feb 8, 2017 · 12 comments
Closed

Memory leak in Signal#discrete #799

mpilquist opened this issue Feb 8, 2017 · 12 comments
Labels
Milestone

Comments

@mpilquist
Copy link
Member

mpilquist commented Feb 8, 2017

This program should run in constant memory but it doesn't:

object SignalDiscreteSanityTest extends App {
  import TestUtil.S
  Stream.eval(async.signalOf[Task, Unit](())).flatMap { signal =>
    signal.discrete.evalMap(a => signal.set(a))
  }.run.unsafeRun
}

Based on some quick heap analysis, it looks like we are leaking resource cleanup -- e.g., a huge LongMap, a ton of Tokens, etc.

Each element through discrete results in a new Stream.bracket. I suspect the finalizers are getting promoted to higher scope due to the async effect of signal.set.

Note: same test using continuous runs in constant memory:

object SignalContinuousSanityTest extends App {
  import TestUtil.S
  Stream.eval(async.signalOf[Task, Unit](())).flatMap { signal =>
    signal.continuous.evalMap(a => signal.set(a))
  }.run.unsafeRun
}
@mpilquist
Copy link
Member Author

BTW, I'm pretty sure this is the cause of the memory leak in time.awakeEvery reported by @AusCoder in Gitter

@mpilquist mpilquist added this to the 0.9.3 milestone Feb 8, 2017
@mpilquist mpilquist added the bug label Feb 8, 2017
@pchlupacek
Copy link
Contributor

@pchlupacek
Copy link
Contributor

I think we will need to create proper Tag for the discrete subscriber and cleanup registration from the outer scope of go.

@pchiusano
Copy link
Contributor

@pchlupacek yup we just spotted the same thing... figuring out fix

@pchlupacek
Copy link
Contributor

@pchiusano @mpilquist just for curiosity any progress on that? Eventually, I can tackle this, as we are about to move part of our production to fs2, with heavy signal usage. lmk pls. I would like also make 9.3 with this patch, or if there is something else worth of backporting from 1.0 lmk

@mpilquist
Copy link
Member Author

I haven't made any progress (was busy with work stuff yesterday). I definitely agree we need a 0.9.3 with this fix. I'll look through the 1.0 commits and see what can be backported.

@pchlupacek
Copy link
Contributor

lmk if you want to fix that or I shall do it. My approach will be to introduce Id/Tag of discrete subscriber and clean it on bracket finalisation, instead on every step. Any thoughts?

@mpilquist
Copy link
Member Author

Sure, have at it.

@pchiusano
Copy link
Contributor

pchiusano commented Feb 9, 2017 via email

@pchlupacek
Copy link
Contributor

@mpilquist, @pchiusano see #802 with backport in #803

@pchlupacek
Copy link
Contributor

also threw in Traverse improvements, hope you won't mind

@mpilquist
Copy link
Member Author

Fixed in 0.9.3 and 1.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants