-
Notifications
You must be signed in to change notification settings - Fork 283
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
KSP 1.9.21-1.0.15 leaking memory and causing OOMs #1653
Comments
That commit is essentially reverting 6bf8193, which is just reverting back to the old behavior for KSP1 therefore should not be causing issues. Do you have a setup that can I can reproduce your OOM issue? |
We are able to repro this in a build that uses persistent workers via https://github.com/bazelbuild/rules_kotlin. Bazel persistent workers are just a standalone JVM processes that accepts and process work requests. As a quick test I added this code to the val clazz = Class.forName("com.google.devtools.ksp.KSObjectCacheManager")
val companion = clazz.getDeclaredField("Companion")
val instance = companion.get(null)
val method = instance.javaClass.getDeclaredMethod("clear")
method.invoke(instance) |
Is there any reason to not tear down the cache along with the |
The reason for tearing down the |
Manually clearing the cache does seem to help. I've ran our benchmark suite a few times against our entire repo and the numbers look consistent with Kotlin 1.9.20 + KSP 1.9.20-1.0.14. Happy to test any other theories if you can think of anything else that might be causing this. |
Interesting, I am wondering why it was not present until 1.9.20-1.0.15, let me try to figure it out before proceeding with a fix. |
Dug a bit deeper just to triple-check the memory leaking theory using Kotlin 1.9.20 + KSP 1.9.20-1.0.14 building all appsObserved memory stays around 1.5gb - 2.5gb for most of the build and never seems to exceed 3gb. I managed to grab a dump that's about 2.5gb in size. Kotlin 1.9.21 + KSP 1.9.21-1.0.15 building all appsObserved memory pretty quickly grows to more than 17gb. Running The KSP worker also eventually locks up during the build once it hits the memory cap and has nothing else to consume. Kotlin 1.9.21 + KSP 1.9.21-1.0.15 + reflection hack to clear wipe the memoryObserved memory consumption remains pretty low. Hands around 3.5 - 4.5gb. Running |
this also causes OOMs for our developers. we are using the Buck build system that has a long lived Buck daemon process |
Can this issue be observed with any 1.0.13 KSP versions? |
@neetopia We see no issues on 1.0.13 & 1.0.14 |
@Bencodes would you be ok if I proceed with your fix for now to unblock impacted users? |
@neetopia I'm fine with that. |
I can also try to throw together a demo project that demonstrates the issue if you want something to debug against. And can provide heap dumps if that's useful. |
That would help, for now I am ok with proceeding with your fix, the cause should be a pointer not released causing GC fail to recycle the cache, we will visit it later. |
Please try 1.9.21-1.0.16 for the fix, thanks for the help with the issue investigation. |
@neetopia we are no longer seeing OOMs/GC thrash on our Bazel builds on 1.0.16, but our Buck builds are still leaking & failing after 2x build time due to GC of leaks in our long-lived Buck daemon process. I'm investigating further to see why |
@jbarr21 Thanks for checking, can you file another issue to track since it looks like a different issue to me? |
Just ran into this while updating Kotlin to 1.9.21 and KSP to 1.9.21-1.0.15 in Anvil. I haven't had a chance to dig into it yet but I've also given the new 1.9.21-1.0.16 release a try which seems to still be resulting in OOMs for us. Also, we are using Gradle for our builds. Related PR: https://github.com/square/anvil/pull/814/files |
Raised #1656 |
Just tested |
@Bencodes is the reflection hack you mentioned the same as the commit in your PR? |
Yes and being used like this: internal class SomeProcessor(
// ...
) : SymbolProcessor {
// ...
override fun finish() {
val clazz = Class.forName("com.google.devtools.ksp.KSObjectCacheManager")
val companion = clazz.getDeclaredField("Companion")
val instance = companion.get(null)
val method = instance.javaClass.getDeclaredMethod("clear")
method.invoke(instance)
}
} |
It looks incorrect to me, in your commit you are calling clear for the class For now if this reflection hack works for anyone on older version (1.0.15), please take a try, otherwise please use 1.0.14 or earlier versions before we figure out a root cause and fixed it. |
Oh wait you are right. I didn't realize that there are two cache managers with the exact same name in the KSP codebase. So then that means calling clear on
|
Isn't this issue resolved with the |
For everyone affected with OOM issue, please try out this snapshot for a fix verification: |
I confirmed that |
@neetopia given fix is verified by two folks, can you go ahead and tag it to a hotfix-version release? |
Fix is shipped with 1.9.22-1.0.17 |
Thanks! @neetopia will the artifacts be uploaded to the 1.9.22-1.0.17 GitHub release? |
KSP
1.9.21-1.0.15
has started leaking memory and causing OOM issues when being used in a persistent worker environment. I suspect it's related to 85f9cac where instances are being placed into a global static list.The text was updated successfully, but these errors were encountered: