Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: give a killed llama-server time to exit before a reload fails (#13622)

Daniel Hanc06e4a1e3d8b
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py
index 67b98a6586f..8c2c672b46b 100644
--- a/studio/backend/core/inference/llama_cpp.py
+++ b/studio/backend/core/inference/llama_cpp.py
@@ -8264,6 +8264,10 @@ def _local_ssl_context() -> ssl.SSLContext:
return ssl.create_default_context()
+# Freeing a large model's GPU memory on a busy driver took over 5 s after SIGKILL; this only bounds a stuck process.
+_SIGKILL_REAP_TIMEOUT_S = 30
+
+
class LlamaCppBackend:
"""Manages a llama-server subprocess for GGUF model inference.
@@ -35623,7 +35627,7 @@ class LlamaCppBackend:
# raised from -- it escapes, and a truly unkillable server would then
# be reported by nothing at all.
logger.warning("llama-server did not exit on SIGTERM, sent SIGKILL")
- self._process.wait(timeout = 5)
+ self._process.wait(timeout = _SIGKILL_REAP_TIMEOUT_S)
except Exception as e:
logger.warning(f"Error killing llama-server process: {e}")
finally:
diff --git a/studio/backend/tests/test_llama_cpp_atexit_quiet.py b/studio/backend/tests/test_llama_cpp_atexit_quiet.py
index bfcb41ac58d..0eed7e43efe 100644
--- a/studio/backend/tests/test_llama_cpp_atexit_quiet.py
+++ b/studio/backend/tests/test_llama_cpp_atexit_quiet.py
@@ -268,3 +268,24 @@ def test_a_raising_logger_still_closes_the_attempt_log_and_names_a_crash(monkeyp
assert backend._llama_log_fh is None
assert path.read_text(encoding = "utf-8").endswith("reason=exited exit_code=3\n")
+
+
+class _SlowToReapProcess(_StubbornProcess):
+ """Exits after SIGKILL, but only once the driver has released its memory."""
+
+ def wait(self, timeout = None):
+ if not self.killed or (timeout or 0) < 10:
+ raise subprocess.TimeoutExpired("llama-server", timeout)
+
+
+def test_a_killed_server_gets_time_to_release_its_memory(monkeypatch):
+ """A reload on a busy GPU failed with "timed out after 5 seconds" while the killed
+ server was still releasing a large model."""
+ monkeypatch.setattr(mod, "logger", _RecordingLogger())
+ backend = _stub()
+ proc = _SlowToReapProcess()
+ backend._process = proc
+
+ backend._kill_process()
+
+ assert proc.killed