ollama icon indicating copy to clipboard operation
ollama copied to clipboard

Ollama should clear temp files on exit.

Open amnweb opened this issue 1 year ago • 2 comments
trafficstars

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

amnweb avatar Feb 22 '24 00:02 amnweb

@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!

mchiang0610 avatar Feb 22 '24 00:02 mchiang0610

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 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

binoychitale avatar Feb 25 '24 04:02 binoychitale