[GH-ISSUE #2658] Ollama should clear temp files on exit. #48088

Closed
opened 2026-04-28 06:45:23 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @amnweb on GitHub (Feb 22, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/2658

Originally assigned to: @dhiltgen on GitHub.

Found that upon exiting, Ollama does not delete temporary files, but upon starting, Ollama creates new identical files again. in temp folder ''..AppData\Local\Temp"

OS: Windows 11

image

Originally created by @amnweb on GitHub (Feb 22, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/2658 Originally assigned to: @dhiltgen on GitHub. Found that upon exiting, Ollama does not delete temporary files, but upon starting, Ollama creates new identical files again. in temp folder ''..AppData\Local\Temp" OS: Windows 11 ![image](https://github.com/ollama/ollama/assets/16545063/8831fff1-d684-4217-bc39-a6aaac5624e9)
GiteaMirror added the bug label 2026-04-28 06:45:23 -05:00
Author
Owner

@mchiang0610 commented on GitHub (Feb 22, 2024):

@amnweb thank you so much for this. We definitely do try to clean up the tmp files on exit. This is definitely a bug. Sorry!

<!-- gh-comment-id:1958467421 --> @mchiang0610 commented on GitHub (Feb 22, 2024): @amnweb thank you so much for this. We definitely do try to clean up the tmp files on exit. This is definitely a bug. Sorry!
Author
Owner

@binoychitale commented on GitHub (Feb 25, 2024):

Hi folks,

I've been trying to look into why this happens, and it turns out that when we use exec.CommandContext: 2a4b128ae3/app/lifecycle/server_windows.go (L10) and call the cancel() method, it seems to internally send a SIGKILL
Source code
image

It also looks like we can set a custom Cancel function to be called when the context is canceled, per this part of the code
image

Does it make sense to update the Cancel hook to send a SIGTERM to the serve command, wait for a pre-defined timeout and then send a kill signal if the process does not exit? ( I think we can check this by inspecting Cmd.ProcessState

cc: @mchiang0610

<!-- gh-comment-id:1962809832 --> @binoychitale commented on GitHub (Feb 25, 2024): Hi folks, I've been trying to look into why this happens, and it turns out that when we use `exec.CommandContext`: https://github.com/ollama/ollama/blob/2a4b128ae3e3a18b10e8701aca2434d401eaa7ba/app/lifecycle/server_windows.go#L10 and call the `cancel()` method, it seems to internally send a `SIGKILL` [Source code](https://cs.opensource.google/go/go/+/refs/tags/go1.22.0:src/os/exec/exec.go;l=465) ![image](https://github.com/ollama/ollama/assets/17764984/ce3d145b-ff45-4eda-bdc5-b018e0b0e453) It also looks like we can set a custom `Cancel` function to be called when the context is canceled, per [this part of the code](https://cs.opensource.google/go/go/+/refs/tags/go1.22.0:src/os/exec/exec.go;l=259) ![image](https://github.com/ollama/ollama/assets/17764984/25879fc8-d71a-4ef5-8562-bfddfc25605a) Does it make sense to update the `Cancel` hook to send a `SIGTERM` to the _serve_ command, wait for a pre-defined timeout and then send a kill signal if the process does not exit? ( I think we can check this by inspecting `Cmd.ProcessState` cc: @mchiang0610
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#48088