fwcd / fwcd/kotlin-language-server

Infinite loop caused by recursion walk

Open
#467 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
2k
Forks
252
PR merge metrics
No merged PRs in 30d

Description

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) {
fun walkIncluded(): Sequence = 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](https://github.com/fwcd/kotlin-language-server/files/11430805/0001-Handle-recursive-walk-infinite-loops-such-as-bazel-s.patch)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in shared/src/main/kotlin/org/javacs/kt/SourceExclusions.kt, especially walkIncluded and its onEnter traversal. Reproduce the Bazel workspace case described in the issue, then verify that the source walk terminates without looping through recursive paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
devtools
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.