kotlin-language-server icon indicating copy to clipboard operation
kotlin-language-server copied to clipboard

Infinite loop caused by recursion walk

Open xinzhengzhang opened this issue 1 year ago • 1 comments

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

xinzhengzhang avatar May 09 '23 13:05 xinzhengzhang

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

xinzhengzhang avatar May 10 '23 03:05 xinzhengzhang