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

The Kotlin Language Server server crashed 5 times in the last 3 minutes. The server will not be restarted.

Open justablob opened this issue 5 years ago • 19 comments

I have just installed this extension in VS Code Insiders 1.26.0 on a Windows 10 x64 machine. However, when opening Kotlin projects, I get the message I put in the title. The Kotlin output window only shows this:

[Info  - 9:52:56 AM] Connection to server got closed. Server will restart.
[Info  - 9:52:56 AM] Connection to server got closed. Server will restart.
[Info  - 9:52:56 AM] Connection to server got closed. Server will restart.
[Info  - 9:52:56 AM] Connection to server got closed. Server will restart.
[Error - 9:52:56 AM] Connection to server got closed. Server will not be restarted.

And when looking in DevTools, I see this:

ERR Message header must separate key and value using :: Error: Message header must separate key and value using :
    at C:\Users\Noah\.vscode-insiders\extensions\fwcd.kotlin-0.1.7\node_modules\vscode-jsonrpc\lib\messageReader.js:68:23
    at Array.forEach (<anonymous>)
    at MessageBuffer.tryReadHeaders (C:\Users\Noah\.vscode-insiders\extensions\fwcd.kotlin-0.1.7\node_modules\vscode-jsonrpc\lib\messageReader.js:65:17)
    at StreamMessageReader.onData (C:\Users\Noah\.vscode-insiders\extensions\fwcd.kotlin-0.1.7\node_modules\vscode-jsonrpc\lib\messageReader.js:194:43)
    at Socket.<anonymous> (C:\Users\Noah\.vscode-insiders\extensions\fwcd.kotlin-0.1.7\node_modules\vscode-jsonrpc\lib\messageReader.js:185:19)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at Pipe.onread (net.js:594:20)

That message is repeated 4 or 5 times in fast succession. Any solutions to this?

C:\Users\Noah\Desktop\kotlin> java -version
  java version "1.8.0_151"
  Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
  Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

C:\Users\Noah\Desktop\kotlin> kotlin -version
  Kotlin version 1.2.60-eap-75 (JRE 1.8.0_151-b12)

justablob avatar Aug 01 '18 08:08 justablob

Tested on Linux and there was no issue so this seems to be a windows only issue. Also hi another Noah!

Strum355 avatar Aug 01 '18 10:08 Strum355

@justablob I have had no trouble running the server on Windows 10 64bit. Could you please try whether this issue persists with stable VSCode?

fwcd avatar Aug 01 '18 14:08 fwcd

Had the same error. I went and changed the source code on messageReader.js to console.log the header since it seemed to be causing the problem. It returned an array containing this:

"ERROR: JAVA_HOME is set to an invalid directory: "

Whoops. Setting the java home environment variable fixed the problem. Maybe it's possible to throw a better error message? I think the issue can be closed unless the original person comes back and says they're still having issues.

RobertAron avatar Aug 29 '18 02:08 RobertAron

@RobertAron That surprises me, because the extension is supposed to show an error dialog in this case:

https://github.com/fwcd/KotlinLanguageServer/blob/c3368728b86f523875c83c24360f7699be2516b1/vscode-extension-src/extension.ts#L19-L23

fwcd avatar Aug 29 '18 12:08 fwcd

The error actually occurred because my JAVA_HOME was set but to the wrong location. Probably a lot more fringe than I initially thought so it's probably not the same issues others are having.

RobertAron avatar Aug 30 '18 00:08 RobertAron

I had the same error, my JAVA_HOME was pointing to a valid 1.6 jdk, changing it to point to 1.8 fixed the error.

kymikoloco avatar Oct 23 '18 19:10 kymikoloco

I'm seeing the same error on OSX, what's strange is as far as I can tell my environment is the same as a coworker's and his is running with no issues.

The Kotlin diagnostic output doesn't show much, I just get the following 5 times and then it quits:

Info  - 10:15:09 AM] main      Connected to client
[Info  - 10:15:09 AM] client    Adding workspace file:///Users/matt/code/pg/mono to source path
[Info  - 10:15:10 AM] client    Adding 151 files under /Users/matt/code/pg/mono to source path
[Info  - 10:15:11 AM] client    Searching for dependencies in workspace root /Users/matt/code/pg/mono
[Info  - 10:15:16 AM] Connection to server got closed. Server will restart.

Is there a way to get additional debugging info regarding why the language server is shutting down?

MattKunze avatar Aug 19 '19 16:08 MattKunze

I'm having the same problem as @MattKunze on macOS. I've enabled verbose tracing in the settings, and there doesn't appear to be any additional info available from this.

[Info  - 10:30:41 AM] client    Adding 1977 files under /Users/andyearnshaw/Projects/dashvis to source path
[Trace - 10:30:42 AM] Received notification 'window/logMessage'.
Params: {
    "type": 3,
    "message": "client    Searching for dependencies in workspace root /Users/andyearnshaw/Projects/dashvis"
}


[Info  - 10:30:42 AM] client    Searching for dependencies in workspace root /Users/andyearnshaw/Projects/dashvis
[Info  - 10:30:46 AM] Connection to server got closed. Server will restart.

andyearnshaw avatar Oct 02 '19 09:10 andyearnshaw

Same issue on VScode with Ubuntu 18.04.03 openjdk 11

festum avatar Oct 14 '19 11:10 festum

I had this issue in our private monorepo. I tracked the cause down to having a node.js node_modules folder in the root of the directory. We internally use a product that uses gradle in the node ecosystem and that caused an error.

It would be supremely helpful if there were a way to see the actual error messages the language server catches prior to closing.

shaunlmason avatar Oct 17 '19 16:10 shaunlmason

We have a mix of node/Kotlin code in our monorepo (and we're using yarn workspaces so the root node_modules tends to contain pretty much everything), but the thing that's weird is it works on some machines and not others. Without better error diagnostics it's really hard to know where to continue to look

MattKunze avatar Oct 17 '19 17:10 MattKunze

I enabled the verbose tracing, and I'm seeing a Java Exception logged about "too many open files." I'm guessing it's trying to recursively traverse my node_modules directory to search for Kotlin files.

Is there a way to tell it only to look at certain Kotlin files?

cspotcode avatar Nov 08 '19 22:11 cspotcode

@cspotcode Thanks – it was the same problem for me.

Deleting node_modules "fixed" the problem... but this is obviously not a good solution 🙁

willvousden avatar Dec 09 '19 12:12 willvousden

I have the same issue. My project is a huge android project with hundreds of modules and it has at least 15000 Kotlin files.

After tracing the source codes, I found the Kotlin Language Server failed on the following method:

/** Searches the folder for all build-files. */
private fun folderResolvers(workspaceRoot: Path, folder: Path, ignored: List<PathMatcher>): Collection<ClassPathResolver> {
    var resolvers = mutableListOf<ClassPathResolver>()

    for (file in Files.list(folder)) {
        // Only test whether non-ignored file is a build-file
        if (ignored.none { it.matches(workspaceRoot.relativize(file)) }) {
            val resolver = asClassPathProvider(file)
            if (resolver != null) {
                resolvers.add(resolver)
                break
            } else if (Files.isDirectory(file)) {
                resolvers.addAll(folderResolvers(workspaceRoot, file, ignored))
            }
        }
    }

    return resolvers
}

https://github.com/fwcd/kotlin-language-server/blob/master/shared/src/main/kotlin/org/javacs/kt/classpath/DefaultClassPathResolver.kt#L22

This method is looking for all the maven / gradle / shell modules from the project root to its subfolder recursively. For example, it searches all of ".build.gradle" or ".build.gradle.kts" to identify it is gradle module or not. The reason to do that is it wants to resolve the dependencies on each maven / gradle / shell module. But this search takes too much time, especially for the huge project. Although it ignores not necessary folders from the project root's ".gitignore", it still causes the Kotlin Language Server failed. My android project has a flat structure and it only has two layers of structure. So it doesn't need to search so deeply. I modify this method to only run two levels of recursion and this modification works for my project. But this solution only works for your projects has two layers of the structure. I have not idea how to traverse the project trees efficiently to resolve all of the dependencies.

colorhaake avatar Dec 20 '19 16:12 colorhaake

This issue still persists even in a pure Kotlin directory with SolusOS, VSCode v1.45.1, and OpenJDK 14.

festum avatar Jun 08 '20 16:06 festum

I had same issue, and tried to solve. If you get this error and you use Java with SDK MAN, try using Java without SDK MAN.

I'd like to share my attempts.

  • Open settings(ctrl + ,) and type "kotlin laguage server"
  • Change 2 configurations below Kotlin > Language Server: Port: 5050 Kotlin > Language Server: Transport: tcp

when I changed the settings of transport layer of Kotlin Language Server, I got the error message in Output tab(Kotlin)

ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

The language server exited, code: 1, signal: null

After some investigation, I got 2 points:

  • the installer is at .vscode-server/data/User/globalStorage/fwcd.kotlin/langServerInstall/server/bin/kotlin-language-server (the error message above is from this script)
  • the script kotlin-language-server seems to be executed earlier than JAVA_HOME is set by SDK MAN.

Though I guessed only JAVA_HOME is important to execute kotlin-language-server, I uninstalled both Java and Kotlin, then re-installed them without SDK MAN.

After I set JAVA_HOME in my .bashrc, the installation script of the language server was successfully completed.

my environment

$ cat /etc/redhat-release 
CentOS Linux release 7.8.2003 (Core)

$ code --version
1.46.1
cd9ea6488829f560dc949a8b2fb789f3cdc05f5d
x64

$ java -version
openjdk version "11.0.7" 2020-04-14 LTS
OpenJDK Runtime Environment Corretto-11.0.7.10.1 (build 11.0.7+10-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.7.10.1 (build 11.0.7+10-LTS, mixed mode)

$ kotlinc -version
info: kotlinc-native 1.3.72-eap-463 (JRE 11.0.7+10-LTS)
Kotlin/Native: 1.3.72

I hope it will be a help for someone in the same problem.

Polarbear08 avatar Jul 04 '20 19:07 Polarbear08

I experienced this issue on VS Code with WSL2. I have installed the extension within WSL2 and tried to use it on Windows 10 2004. What I did (in part based on @Polarbear08's solution):

  1. Explicitly install openjdk-14-jdk-headless on WSL2.
  2. Change 2 configurations below Kotlin > Language Server: Port: 5050 Kotlin > Language Server: Transport: tcp

  3. Install Kotlin compiler.
curl -sSLOf https://github.com/JetBrains/kotlin/releases/download/v1.3.72/kotlin-native-linux-1.3.72.tar.gz
tar zxf kotlin-native-linux-1.3.72.tar.gz
sudo mv kotlin-native-linux-1.3.72 /usr/bin/kotlin-native-linux-1.3.72
export PATH="$PATH:/usr/bin/kotlin-native-linux-1.3.72/bin" # Optionally, add to .bashrc or something.
which kotlinc # Check if it works.
  1. Restart VS Code.

Now the language server starts up properly.

WSL2's OS: Debian Linux bullseye

theAkito avatar Jul 11 '20 16:07 theAkito

You need to tell the extension a java 11 path "kotlin.java.home": "/Users/sdykae/.jabba/jdk/[email protected]/Contents/Home",

sdykae avatar Nov 17 '22 18:11 sdykae

I ran the extension in a dev container and my problem was, that I apparently hadn't installed kotlin. Inspired by the answer from @theAkito I added the following to my Dockerfile:

# download latest kotlin release
RUN curl -sSLOf https://github.com/JetBrains/kotlin/releases/download/v1.8.0/kotlin-native-linux-x86_64-1.8.0.tar.gz
# extract the contents of the tar.gz file
RUN tar -zxf kotlin-native-linux-x86_64-1.8.0.tar.gz
# move the contents of the extracted folder to /usr/bin/kotlin
RUN mv kotlin-native-linux-x86_64-1.8.0 /usr/bin/kotlin
# delete tar
RUN rm kotlin-native-linux-x86_64-1.8.0.tar.gz
# update path
ENV PATH="${PATH}:/usr/bin/kotlin"

and rebuilt my container. Now it seems to work.

F1nnM avatar Jan 19 '23 16:01 F1nnM