kotlin-language-server
kotlin-language-server copied to clipboard
Infinite loop caused by recursion walk
I am integrating with bazel system, but the process found that the walk function is not handled correctly, resulting in an infinite loop. I tried to make a patch and it has been successfully integrated in bazel with 'manually' provide a list of dependencies through a shell script, located either at [project root]/kls-classpath
+++ b/shared/src/main/kotlin/org/javacs/kt/SourceExclusions.kt
@@ -18,7 +18,14 @@ class SourceExclusions(private val workspaceRoots: Collection<Path>) {
fun walkIncluded(): Sequence<Path> = workspaceRoots.asSequence().flatMap { root ->
root.toFile()
.walk()
- .onEnter { isPathIncluded(it.toPath()) }
+ .onEnter {
+ val enter = if (it.canonicalPath != it.absolutePath) {
+ false
+ } else {
+ isPathIncluded(it.toPath())
+ }
+ enter
+ }
.map { it.toPath() }
}
0001-Handle-recursive-walk-infinite-loops-such-as-bazel-s.patch
I saw a similar problem with softlink #464 , but I don't think restricting traversal through .gitignore is the same thing as this. From the documentation https://docs.w3cub.com/kotlin/api/latest/jvm/stdlib/kotlin.io/java.io.-file/walk it seems that the walkapi does not have other options to handle infinite recursion. I briefly tried the file walk api of other languages stdlib, such as python, which does not seem to have this problem