-
-
Notifications
You must be signed in to change notification settings - Fork 246
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
Fix memory leak #1197
Fix memory leak #1197
Conversation
@@ -190,7 +190,7 @@ private[monix] object TaskBracket { | |||
val fb = | |||
try use(value) | |||
catch { case NonFatal(e) => Task.raiseError(e) } | |||
fb.flatMap(releaseFrame) | |||
fb.flatMap(releaseFrame).flatMap(r => Task { conn.pop(); r }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we could call ctx.connection.pop()
in unsafeRecover
and unsafeApply
which I removed by mistake in the PR you mentioned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I put this call there, tests fail. I think it breaks the feature you did in that PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see.
I think we could do it in a similar way to Cats IO: https://github.com/typelevel/cats-effect/blob/master/core/shared/src/main/scala/cats/effect/internals/IOBracket.scala#L189
so
private[this] val disableUncancelableAndPop: (Any, Throwable, Context, Context) => Context =
(_, _, old, _) => {
old.connection.pop()
old
}
instead of a null
in ContextSwitch
.
I'm not able to check right now but the testa should pass since they are passing for Cats IO and hopefully the memory leak will go away :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, it works fine. Thank you!
Big thank you!
I think we're fine skipping the test if it takes a long time to go out of memory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Do you need a snapshot version release / official release right now?
I'm hoping to finish everything for 3.2.2
release within 1-2 weeks but I am considering to pull the trigger earlier considering the severity of the issue
I rolled back Monix to 3.1.0 in my project, so it can wait for some time. |
After upgrading Monix to the latest version I found a memory leak related to the new bracket implementation.
Git bisect shows the culprit commit:
#1120
Below is a simple piece of code that reproduces the issue:
F.guarantee(F.unit)(F.unit).foreverM
- it fails with OutOfMemoryError on monix.eval.Task, but works fine with cats.effect.IOI'm not sure if this is a correct fix of the issue and I need help to write a test on this case