Has anyone experienced their session alive file no...
# gradle
o
Has anyone experienced their session alive file not being cleaned up after a build finishes, causing the warning
Detected multiple Kotlin daemon sessions at
to appear after starting and completing a new build? I am upgrading the AndroidX repo to use K2 and encountering a new issue on Mac only. The warning
Detected multiple Kotlin daemon sessions at
now appears. Using
watch -n 1 ls ../../out/.kotlin/sessions
, I noticed a file is added to
out/.kotlin/sessions/
during the configuration stage (buildSrc) and again during the execution stage whenever a
compileKotlin
task occurs. The compiler logs show two different session files are created due to two different client alive files (prefixed with
kotlin-compiler-in-buildrc
and
kotlin-compiler-in-androidx
). However, it seems that
kotlin-compiler-in-buildrc
does not clean up after finishing
t
if you are using different Kotlin Gradle plugins versions - you may see such issue. For example
kotlin-dsl
plugin transitively brings own version of KGP for
buildSrc
module compilation.
o
I ran
./gradlew :buildSrc:dependencies
and the KGP version was 2.0
I found out why this was working on 1.9.4 and before. The
salive
files used to be stored in different paths for buildSrc vs other modules in the project. I attached a debugger and added a breakpoint
KotlinGradleFinishBuildHandler
for version 1.9.4, and looking at the value of
sessionsDir
for buildSrc , it is:
/Users/omarismail/Desktop/androidx-main/superproject/frameworks/support/buildSrc/.gradle/kotlin/sessions
and for androidx it is:
/Users/omarismail/Desktop/androidx-main/superproject/out/gradle-project-cache/kotlin/sessions
. In 2.0, the session files are stored in the same location (
/Users/omarismail/Desktop/androidx-main/superproject/out/.kotlin/sessions
, causing the error to appear.
Is this a bug?
CC: @aurimas
t
you need to call
:buildSrc:buildEnvironment
task to check which KGP version is used to compile
buildSrc
o
Just did so now and it was all 2.0.0:
Copy code
classpath
\--- org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0
     +--- org.jetbrains.kotlin:kotlin-gradle-plugins-bom:2.0.0
     |    +--- org.jetbrains.kotlin:kotlin-gradle-plugin-api:2.0.0 (c)
     |    +--- org.jetbrains.kotlin:kotlin-gradle-plugin-model:2.0.0 (c)
     |    +--- org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0 (c)
     |    +--- org.jetbrains.kotlin:kotlin-gradle-plugin-annotations:2.0.0 (c)
     |    +--- org.jetbrains.kotlin:kotlin-native-utils:2.0.0 (c)
     |    \--- org.jetbrains.kotlin:kotlin-tooling-core:2.0.0 (c)
     +--- org.jetbrains.kotlin:kotlin-gradle-plugin-api:2.0.0
     |    +--- org.jetbrains.kotlin:kotlin-gradle-plugins-bom:2.0.0 (*)
     |    +--- org.jetbrains.kotlin:kotlin-gradle-plugin-annotations:2.0.0
     |    +--- org.jetbrains.kotlin:kotlin-native-utils:2.0.0
     |    |    +--- org.jetbrains.kotlin:kotlin-util-io:2.0.0
     |    |    \--- org.jetbrains.kotlin:kotlin-util-klib:2.0.0
     |    |         \--- org.jetbrains.kotlin:kotlin-util-io:2.0.0
     |    \--- org.jetbrains.kotlin:kotlin-tooling-core:2.0.0
     +--- org.jetbrains.kotlin:kotlin-gradle-plugin-model:2.0.0
     |    +--- org.jetbrains.kotlin:kotlin-gradle-plugin-api:2.0.0 (*)
     |    \--- org.jetbrains.kotlin:kotlin-gradle-plugins-bom:2.0.0 (*)
     +--- org.jetbrains.kotlin:kotlin-gradle-plugin-idea:2.0.0
     |    +--- org.jetbrains.kotlin:kotlin-tooling-core:2.0.0
     |    \--- org.jetbrains.kotlin:kotlin-gradle-plugin-annotations:2.0.0
     +--- org.jetbrains.kotlin:kotlin-gradle-plugin-idea-proto:2.0.0
     |    \--- org.jetbrains.kotlin:kotlin-gradle-plugin-idea:2.0.0 (*)
     +--- org.jetbrains.kotlin:kotlin-klib-commonizer-api:2.0.0
     |    \--- org.jetbrains.kotlin:kotlin-native-utils:2.0.0 (*)
     +--- org.jetbrains.kotlin:kotlin-build-tools-api:2.0.0
     +--- org.jetbrains.kotlin:kotlin-build-statistics:2.0.0
     |    +--- org.jetbrains.kotlin:kotlin-build-tools-api:2.0.0
     |    \--- com.google.code.gson:gson:2.8.9
     +--- org.jetbrains.kotlin:kotlin-compiler-runner:2.0.0
     |    +--- org.jetbrains.kotlin:kotlin-daemon-client:2.0.0
     |    \--- org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.5.0
     +--- org.jetbrains.kotlin:kotlin-util-klib:2.0.0 (*)
     \--- org.jetbrains.kotlin:kotlin-compiler-embeddable:2.0.0
          +--- org.jetbrains.kotlin:kotlin-daemon-embeddable:2.0.0
          \--- org.jetbrains.intellij.deps:trove4j:1.0.20200330
I just created a minimal example (one Kotlin project and buildSrc), and when I run:
./gradlew :omar:compileKotlin -Pkotlin.project.persistent.dir=dump --no-configuration-cache --rerun-tasks
I get the error "w: Detected multiple Kotlin daemon sessions at" This only occurs if I set
-Pkotlin.project.persistent.dir
.
t
could you share it?
o
yep, one sec let me upload to github
./gradlew  :omar:compileKotlin -Pkotlin.project.persistent.dir=dump --no-configuration-cache --rerun-tasks
to reproduce the error
Maybe one solution could be to pass in
projectName
as a parameter as well to
KotlinGradleBuildServices
and then pass that in to
buildHandler.buildFinished
. In that function, we can do the count check and delete only files which contain
projectName
https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-gradle-plug[…]org/jetbrains/kotlin/gradle/plugin/KotlinGradleBuildServices.kt
If that works, Id be happy to send a PR
Actually, that would only work if we also add the projectName to the
salive
file. I thought it had the project name as part of the file but that's not true, only the
alive
file does
t
So when you don't specify
-Pkotlin.project.persistent.dir=dump
- still two session files are created, but in different directories: •
buildSrc/.kotlin/sessions/
.kotlin/sessions
This is happening because Gradle isolates classloaders of different projects and virtually there are two KGP instances used to build the project. By passing
-Pkotlin.project.persistent.dir=dump
you are forcing single location for all projects, so two session files are created in the same
dumb/sessions
directory. This is possibly incorrect detector that tries to ensure only one Kotlin daemon session is used per-project. We need to discuss it further inside the team. Could you also create an issue for this?
112 Views