fix: Ollama-Adapter räumt die Prozessgruppe auch bei Zeitlimit und frühem Ende auf (#1165); Version 0.1.15-rc21

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GmHhg6k5Hxh8GpVW7od4Di
This commit is contained in:
2026-11-21 00:18:48 +01:00
parent f06340b6e6
commit fae4bba396
5 changed files with 26 additions and 4 deletions

View File

@ -270,11 +270,16 @@ impl OllamaEngine {
.spawn()
.map_err(|e| AdapterError::Spawn(format!("{}: {e}", self.config.binary.display())))?;
// Nach dem Beenden liefert `child.id()` nichts mehr; der Gruppenführer hat die PID der Gruppe.
let pgid = child.id();
let timeout = Duration::from_secs(self.config.ready_timeout_secs);
let started = Instant::now();
loop {
if let Ok(Some(status)) = child.try_wait() {
tracing::warn!(exit_code = status.code(), "ollama serve endete beim Start");
if let Some(pgid) = pgid {
terminate_group(pgid, Duration::from_secs(5)).await;
}
return Err(AdapterError::ExitedEarly {
code: status.code(),
log_tail: log_tail(&log_path, 20),
@ -290,6 +295,10 @@ impl OllamaEngine {
);
let _ = child.start_kill();
let _ = child.wait().await;
// Auch Prozesse der Gruppe beenden (am echten Dienst nachgestellt: sonst bleiben sie verwaist).
if let Some(pgid) = pgid {
terminate_group(pgid, Duration::from_secs(5)).await;
}
return Err(AdapterError::NotReady {
seconds: self.config.ready_timeout_secs,
log_tail: log_tail(&log_path, 20),
@ -304,8 +313,11 @@ impl OllamaEngine {
"ollama serve ist bereit"
);
// Mit `process_group(0)` ist die Gruppen-ID die PID des Servers.
let pgid = child.id().unwrap_or(0);
Ok(Server { child, port, pgid })
Ok(Server {
pgid: pgid.unwrap_or(0),
child,
port,
})
}
async fn get_text(&self, url: &str, timeout_secs: u64) -> Option<String> {

View File

@ -39,6 +39,9 @@ if mode == "crash":
print("fake-ollama: error: could not bind", file=sys.stderr, flush=True)
sys.exit(4)
if mode == "hang":
# Wie ein Server, der beim Start schon einen Hilfsprozess in seiner Gruppe hat (Runner).
runner = subprocess.Popen(["sleep", "15"])
print(f"fake-ollama: runner {runner.pid}", flush=True)
signal.signal(signal.SIGTERM, signal.SIG_DFL)
while True:
time.sleep(1)

View File

@ -239,6 +239,13 @@ async fn server_der_nie_bereit_wird_fuehrt_zur_zeitueberschreitung_und_wird_been
);
let pid = pid_from_log(&server_log(&f));
assert!(wait_until_gone(pid).await, "Prozess blieb zurück");
// #1165, am echten Dienst nachgestellt: Auch ein Hilfsprozess der Gruppe darf nicht zurückbleiben.
for runner in runner_pids(&server_log(&f)) {
assert!(
wait_until_gone(runner).await,
"Hilfsprozess {runner} blieb nach der Zeitüberschreitung zurück"
);
}
}
#[tokio::test]