Open eboudrant opened 9 months ago
I experience similar issue. There are 125 modules in the project. YourKit points to a potential deadlock in this thread with comment: "It seems that the following threads have not changed their stack for more than 10 seconds".
The stacktrace doesn't mention any ksp work, but this problem happens only when ksp is enabled in the project.
Is there any other data that would be helpful? Unfortunately, I can't share the project as it's closed-source.
When I run build with Gradle logs (--debug
) and the build stucks on the ksp task, this sequence is logged repeatedly:
I experienced the same and it turned out there is a freezed Kotlin deamon process. I killed the process and get unstuck. So the problem is probably not ksp but Kotlin daemon.
We also just started seeing this problem for our local developers.
We only started having it when updating from 1.9.20-1.0.14
to 1.9.24-1.0.20
- our workaround now is to ask people to kill the kotlin daemon
We kept having people encounter this issue and waste a lot of time on it, so in our build I have added something to try to auto detect and fix the issue to mitigate it for now.
I added a timeout setting on the KSP task
tasks.withType(KspTaskJvm).configureEach {
it.timeout = Duration.ofMinutes(3)
}
And then in a build listener I check for the ksp timeout and can kill the kotlin daemon and print an error message explaining what happened
boolean taskFailed = event.result instanceof FailureResult
if (taskFailed) {
def kspTimeoutFailure = (event.result as FailureResult).failures.find { failure ->
event.descriptor.name.containsIgnoreCase("ksp") &&
failure.description.containsIgnoreCase("Timeout has been exceeded")
}
if (kspTimeoutFailure != null) {
def command = ["/bin/bash", "-c", "jps | grep -E 'KotlinCompileDaemon' | awk '{print \$1}' | xargs kill -9 || true"]
def killKotlinProcess = command.execute(null, parameters.getRootDir().get())
killKotlinProcess.waitFor()
// print some error message to the user
....
+1 to this being a kotlin daemon issue.
I wrote the original dagger issue linked to this issue. I last tried this with kotlin 1.9.22
and it would always hang. I've recently updated kotlin to 1.9.24
and ksp to 1.9.24-1.0.20
and was finally able to get our project to compile.
I then used the gradle-profiler to compare dagger-android KSP vs KAPT build times and ran into some extremely long incremental build times where the underlying issue seems to be in the Kotlin daemon.
When I ran using a warm daemon, I had a couple incremental builds reach 25 minutes. Here's a screengrab from Develocity showing one of those builds where almost all the time was in the root module's ksp task.
Here's the raw output and build times before I killed the run.
* Running scenario Assemble Debug and make ABI change in :shared:dto module using Gradle 8.8 (scenario 1/1)
* Stopping daemons
* Running warm-up build #1
Execution time 941229 ms
* Running warm-up build #2
Execution time 558732 ms
* Running warm-up build #3
Execution time 973589 ms
* Running warm-up build #4
Execution time 627549 ms
* Running warm-up build #5
Execution time 1194450 ms
* Running warm-up build #6
Execution time 1505849 ms
* Running measured build #1
Execution time 1526739 ms
* Running measured build #2
Execution time 597678 ms
* Running measured build #3
// killed manually
I then ran the exact same scenario with the --cold-daemon
flag so it would get a new daemon for each run and no build (besides the warmup build) took longer than 4.5 minutes.
* Running scenario Assemble Debug and make ABI change in :shared:dto module using Gradle 8.8 (scenario 1/1)
* Stopping daemons
* Running cleanup for warm-up build #1
* Stopping daemons
* Running warm-up build #1
Execution time 501316 ms
* Running cleanup for measured build #1
* Stopping daemons
* Running measured build #1
Execution time 228039 ms
* Running cleanup for measured build #2
* Stopping daemons
* Running measured build #2
Execution time 240739 ms
* Running cleanup for measured build #3
* Stopping daemons
* Running measured build #3
Execution time 205670 ms
* Running cleanup for measured build #4
* Stopping daemons
* Running measured build #4
Execution time 231068 ms
* Running cleanup for measured build #5
* Stopping daemons
* Running measured build #5
Execution time 241298 ms
* Running cleanup for measured build #6
* Stopping daemons
* Running measured build #6
Execution time 226104 ms
* Running cleanup for measured build #7
* Stopping daemons
* Running measured build #7
Execution time 221297 ms
* Running cleanup for measured build #8
* Stopping daemons
* Running measured build #8
Execution time 235292 ms
* Running cleanup for measured build #9
* Stopping daemons
* Running measured build #9
Execution time 248072 ms
* Running cleanup for measured build #10
* Stopping daemons
* Running measured build #10
Execution time 242071 ms
* Stopping daemons
KSP 2.0.20-1.0.25 is just released and may have fixed this issue. Would you mind to give it a try?
We recently moved to ksp from kapt for dagger and we're facing some build getting stuck. Gradle is stuck on
kspDebugKotlin
on random module using dagger ksp.We're using :
We have ~300 modules.
I was able to get some thread stacks using YourKit :
I can't really confirm but it seems it only happen when I have Android Studio open.
Originally reported here : https://github.com/google/dagger/issues/4233