From d0ddf5d6ac50be6c9710e6c00f298604040007bb Mon Sep 17 00:00:00 2001 From: zerone0x Date: Thu, 5 Mar 2026 06:48:40 +0100 Subject: [PATCH] fix(kotlin): redirect idea.system.path to prevent stale /tmp dirs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit KLS is built on IntelliJ's platform, which by default creates a new ~52 MB idea-system/ directory in /tmp for each instance. These directories are never cleaned up on shutdown. On tmpfs systems (the default on modern Linux) this causes unbounded RAM consumption — e.g. 329 accumulated directories totalling 30 GiB after repeated test runs. Fix: append -Didea.system.path=/kotlin_language_server/system/ to JAVA_TOOL_OPTIONS in create_launch_command_env(). This redirects IntelliJ to a fixed, bounded per-project cache directory that also persists across sessions for faster restarts. Fixes #1087 Co-Authored-By: Claude --- .../kotlin_language_server.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/solidlsp/language_servers/kotlin_language_server.py b/src/solidlsp/language_servers/kotlin_language_server.py index ac13ab2b7..a64b92b66 100644 --- a/src/solidlsp/language_servers/kotlin_language_server.py +++ b/src/solidlsp/language_servers/kotlin_language_server.py @@ -14,6 +14,13 @@ ls_specific_settings: kotlin: jvm_options: '-Xmx4G -XX:+UseG1GC' + +IntelliJ system directory: + KLS is built on IntelliJ's platform, which by default creates a new ~52 MB + idea-system/ directory in /tmp for each instance. These directories + are never cleaned up, which can exhaust RAM on tmpfs systems after many runs. + Serena redirects idea.system.path to /kotlin_language_server/system/, + making it a bounded per-project cache that persists across sessions (faster restarts). """ import logging @@ -146,7 +153,18 @@ def create_launch_command_env(self) -> dict[str, str]: else: jvm_options = DEFAULT_KOTLIN_JVM_OPTIONS - env["JAVA_TOOL_OPTIONS"] = jvm_options + # Redirect IntelliJ's system directory to a stable path under ls_resources_dir. + # Without this, each KLS instance creates a new ~52 MB /tmp/idea-system/ directory + # that is never removed on shutdown. On tmpfs systems this causes unbounded RAM consumption + # (e.g. 329 stale directories totalling 30 GiB after repeated test runs). + # Using a fixed path makes it a bounded per-project cache and preserves the IntelliJ index + # across sessions for faster restarts. + system_dir = os.path.join(self._ls_resources_dir, "kotlin_language_server", "system") + os.makedirs(system_dir, exist_ok=True) + idea_system_path_opt = f"-Didea.system.path={system_dir}" + jvm_options_full = f"{jvm_options} {idea_system_path_opt}".strip() if jvm_options else idea_system_path_opt + + env["JAVA_TOOL_OPTIONS"] = jvm_options_full return env @staticmethod