-
Notifications
You must be signed in to change notification settings - Fork 530
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
IODeferred
's CallbackStack
becomes unboundedly large
#3935
Comments
So are we sure this is growing unboundedly? The printlns don't really show that. If you squint, it does kinda look like half-ish is being cleared each time. |
Yes, half-ish of the total is being cleared each time, but each time the total has doubled in size. You can run my reproducer with a larger |
Not each time though. We repeat clearance points several times.
It certainly feels like something here is wrong, but I'm not sure if it's a conventional example of unbounded growth. |
You're right, it's not each time, sorry. Every time we |
Ah I see what you're pointing out. Okay gotcha. I'm surprised the off by one fix doesn't correct it then… |
We should expect |
@mernst-github would you be able to post a self-contained reproducer somewhere? Thanks! |
I can see the printed values gradually plunge into negative territory. |
@mernst-github thanks, I tried that before, but I was unable to replicate your result, I probably did something wrong/different. A self-contained reproducer would help a lot :) e.g. a branch of CE with your reproducer in the |
If I'm not mistaken the 'pack' logic can overcount when called concurrently, since it may clear the same cell twice, for example like so:
=> 2 cells cleared, but c2 got double-counted => clearCounter decremented by 3 |
Some context to start: Cats Effects has been having memory leaks in CallbackStack since version 3.4.3. See for example: typelevel/cats-effect#3935 I've been facing this memory leak in an application using fs2-kafka, and found that I'm not the only one (typelevel/cats-effect#3973). Using a simple consumer > produce stream application, I monitored the size of the CallbackStack using the following command: ``` while sleep 1; do jcmd <pid> GC.class_histogram | grep 'cats.effect.CallbackStack$Node' ; done ``` I found that swapping the `F.race(shutdown, fetch)` for `fetch` stops the memory leak. This should not be an issue because the Stream is anyway interrupted on `.interruptWhen(F.race(shutdown, stopReqs.get).void.attempt)`, but I'm not 100% convinced of this.
Some context to start: Cats Effects has been having memory leaks in CallbackStack since version 3.4.3. See for example: typelevel/cats-effect#3935 I've been facing this memory leak in an application using fs2-kafka, and found that I'm not the only one (typelevel/cats-effect#3973). Using a simple consumer > produce stream application, I monitored the size of the CallbackStack using the following command: ``` while sleep 1; do jcmd <pid> GC.class_histogram | grep 'cats.effect.CallbackStack$Node' ; done ``` I found that swapping the `F.race(shutdown, fetch)` for `fetch` stops the memory leak. This should not be an issue because the Stream is anyway interrupted on `.interruptWhen(F.race(shutdown, stopReqs.get).void.attempt)`, but I'm not 100% convinced of this. Co-authored-by: Adrien Bestel <adrien.bestel@daimlertruck.com>
h/t @mernst-github in #3359 (comment).
Minimizer:
Then I replaced the terminating
()
here withprintln(clearCounter.get())
:cats-effect/core/shared/src/main/scala/cats/effect/IODeferred.scala
Lines 29 to 35 in 2637a5e
Here is the output:
The text was updated successfully, but these errors were encountered: