Repository: ollama
Issue: qwen 2.5 coder stuck "Stopping"
Labels: bug

### What is the issue?

I have an ollama server alone on a server with a L4 Nvidia card : 

Ubuntu 22.04.5 LTS (GNU/Linux 5.15.0-122-generic x86_64)
NVIDIA-SMI 550.107.02             Driver Version: 550.107.02     CUDA Version: 12.4

The only environment variable I've configured is Environment="OLLAMA_KEEP_ALIVE=360m" (tried various values)

And the ollama server hosts only one model 
qwen2.5-coder:latest    2b0496514337    4.7 GB    27 hours ago

ollama version is 0.5.4

And this ollama server is used for an internal copilot tool in my company (mainly with continue plugin). We use it also for the embedding (it may be the problem, as you'll see).

Sometimes, the server doesn't handle new queries. There aren't any reply at all, continue plugin waits indefinitely for an answer.
"ollama ps" shows this
NAME                    ID              SIZE      PROCESSOR    UNTIL            
qwen2.5-coder:latest    2b0496514337    6.0 GB    100% GPU     Stopping...

The only method I've found is to restart the service.

Since yesterday, I've got a crontab that every minute checks the status and restarts ollama if it seems stuck. I have a log to have the history.

It happened today again, so I've looked at ollama log, and may have found something.

My log is this : 
Thu Dec 19 12:47:01 UTC 2024 - Server is running normally.
Thu Dec 19 12:48:01 UTC 2024 - Detected 'Stopping...' status. Restarting the server...

So I've looked at what happened before, and I've got this

```
Dec 19 12:43:01 copilot ollama[3122]: [GIN] 2024/12/19 - 12:43:01 | 200 |       28.31µs |       127.0.0.1 | HEAD     "/"
Dec 19 12:43:01 copilot ollama[3122]: [GIN] 2024/12/19 - 12:43:01 | 200 |       31.81µs |       127.0.0.1 | GET      "/api/ps"
Dec 19 12:44:01 copilot CRON[44051]: (root) CMD (/root/ollama_detector.sh)
Dec 19 12:44:01 copilot ollama[3122]: [GIN] 2024/12/19 - 12:44:01 | 200 |       29.14µs |       127.0.0.1 | HEAD     "/"
Dec 19 12:44:01 copilot ollama[3122]: [GIN] 2024/12/19 - 12:44:01 | 200 |       25.74µs |       127.0.0.1 | GET      "/api/ps"
Dec 19 12:45:01 copilot CRON[44068]: (root) CMD (/root/ollama_detector.sh)
Dec 19 12:45:01 copilot ollama[3122]: [GIN] 2024/12/19 - 12:45:01 | 200 |      27.819µs |       127.0.0.1 | HEAD     "/"
Dec 19 12:45:01 copilot ollama[3122]: [GIN] 2024/12/19 - 12:45:01 | 200 |       27.72µs |       127.0.0.1 | GET      "/api/ps"
Dec 19 12:45:29 copilot ollama[3122]: [GIN] 2024/12/19 - 12:45:29 | 200 |        30m40s |   145.239.103.2 | POST     "/api/embed"
Dec 19 12:46:01 copilot CRON[44083]: (root) CMD (/root/ollama_detector.sh)
Dec 19 12:46:01 copilot ollama[3122]: [GIN] 2024/12/19 - 12:46:01 | 200 |      32.771µs |       127.0.0.1 | HEAD     "/"
Dec 19 12:46:01 copilot ollama[3122]: [GIN] 2024/12/19 - 12:46:01 | 200 |      28.599µs |       127.0.0.1 | GET      "/api/ps"
Dec 19 12:46:10 copilot ollama[3122]: [GIN] 2024/12/19 - 12:46:10 | 200 |        31m22s |   145.239.103.2 | POST     "/api/embed"
Dec 19 12:46:46 copilot ollama[3122]: [GIN] 2024/12/19 - 12:46:46 | 200 |        31m57s |   145.239.103.2 | POST     "/api/embed"
Dec 19 12:47:01 copilot CRON[44098]: (root) CMD (/root/ollama_detector.sh)
Dec 19 12:47:01 copilot ollama[3122]: [GIN] 2024/12/19 - 12:47:01 | 200 |      29.859µs |       127.0.0.1 | HEAD     "/"
Dec 19 12:47:01 copilot ollama[3122]: [GIN] 2024/12/19 - 12:47:01 | 200 |       31.32µs |       127.0.0.1 | GET      "/api/ps"
Dec 19 12:48:01 copilot CRON[44115]: (root) CMD (/root/ollama_detector.sh)
Dec 19 12:48:01 copilot ollama[3122]: [GIN] 2024/12/19 - 12:48:01 | 200 |      26.699µs |       127.0.0.1 | HEAD     "/"
Dec 19 12:48:01 copilot ollama[3122]: [GIN] 2024/12/19 - 12:48:01 | 200 |       22.65µs |       127.0.0.1 | GET      "/api/ps"
Dec 19 12:48:01 copilot systemd[1]: Stopping Ollama Service...
```
So, it seems that the server was "ok" for 5 minutes before my cron detected something.

But actually, the previous line is : 
`Dec 19 12:42:52 copilot ollama[3122]: time=2024-12-19T12:42:52.483Z level=ERROR source=routes.go:479 msg="embedding generation failed" error="context canceled"
`

And before this line, from 12:42:13 up to the previous line, the log is filled with 23 493 lines of log (!)

It looks like this

```
Dec 19 12:42:52 copilot ollama[3122]: time=2024-12-19T12:42:52.479Z level=INFO source=server.go:875 msg="aborting embedding request due to client closing the connection"
Dec 19 12:42:52 copilot ollama[3122]: time=2024-12-19T12:42:52.481Z level=INFO source=server.go:875 msg="aborting embedding request due to client closing the connection"
Dec 19 12:42:52 copilot ollama[3122]: message repeated 6 times: [ time=2024-12-19T12:42:52.481Z level=INFO source=server.go:875 msg="aborting embedding request due to client closing the connection"]
Dec 19 12:42:52 copilot ollama[3122]: time=2024-12-19T12:42:52.479Z level=INFO source=server.go:875 msg="aborting embedding request due to client closing the connection"
Dec 19 12:42:52 copilot ollama[3122]: time=2024-12-19T12:42:52.479Z level=INFO source=server.go:875 msg="aborting embedding request due to client closing the connection"
Dec 19 12:42:52 copilot ollama[3122]: time=2024-12-19T12:42:52.481Z level=INFO source=server.go:875 msg="aborting embedding request due to client closing the connection"
Dec 19 12:42:52 copilot ollama[3122]: message repeated 55 times: [ time=2024-12-19T12:42:52.481Z level=INFO source=server.go:875 msg="aborting embedding request due to client closing the connection"]

```

Seems somethhing wrong, don't you think ?

By the way, when my crontab restarted ollama, I've had thousands of other log lines like this before seeing the log for the server startup

### OS

Linux

### GPU

Nvidia

### CPU

Intel

### Ollama version

0.5.4