Unverified Commit 0195d6a2 authored by Josh's avatar Josh Committed by GitHub
Browse files

Merge pull request #5188 from ollama/jyan/tmpdir2

fix: skip os.removeAll() if PID does not exist
parents fedf7163 662568d4
...@@ -77,20 +77,27 @@ func cleanupTmpDirs() { ...@@ -77,20 +77,27 @@ func cleanupTmpDirs() {
continue continue
} }
raw, err := os.ReadFile(filepath.Join(d, "ollama.pid")) raw, err := os.ReadFile(filepath.Join(d, "ollama.pid"))
if err == nil { if err != nil {
pid, err := strconv.Atoi(string(raw)) slog.Warn("failed to read ollama.pid", "path", d, "error", err)
if err == nil { // No pid, ignore this tmpdir
if proc, err := os.FindProcess(pid); err == nil && !errors.Is(proc.Signal(syscall.Signal(0)), os.ErrProcessDone) { continue
// Another running ollama, ignore this tmpdir
continue
}
}
} else {
slog.Debug("failed to open ollama.pid", "path", d, "error", err)
} }
err = os.RemoveAll(d)
pid, err := strconv.Atoi(string(raw))
if err != nil { if err != nil {
slog.Debug("unable to cleanup stale tmpdir", "path", d, "error", err) slog.Warn("failed to parse pid", "path", d, "error", err)
continue
}
proc, err := os.FindProcess(pid)
if err == nil && !errors.Is(proc.Signal(syscall.Signal(0)), os.ErrProcessDone) {
slog.Warn("found running ollama", "pid", pid, "path", d)
// Another running ollama, ignore this tmpdir
continue
}
if err := os.Remove(d); err != nil {
slog.Warn("unable to cleanup stale tmpdir", "path", d, "error", err)
} }
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment