[PR #4187] [MERGED] Fix rare nil pointer dereference when model unloads #37282

Closed
opened 2026-04-22 21:59:36 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/4187
Author: @jmorganca
Created: 5/6/2024
Status: Merged
Merged: 5/6/2024
Merged by: @jmorganca

Base: mainHead: jmorganca/unload-fix


📝 Commits (1)

  • 8a51d4a unload in critical section

📊 Changes

2 files changed (+7 additions, -10 deletions)

View changed files

📝 server/sched.go (+4 -4)
📝 server/sched_test.go (+3 -6)

📄 Description

While testing concurrency I noticed a segfault happen occasionally when loading, canceling, and loading the same model repeatedly over and over again with a script like this:

#!/bin/bash

# Command to run
COMMAND="ollama run llama3 hello"

# Number of times to run the command concurrently
N=100

# Running the command N times concurrently
for i in $(seq 1 $N); do
    $COMMAND &
done

The error looked like this:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x101298ae0]

goroutine 51 [running]:
github.com/ollama/ollama/server.(*runnerRef).needsReload(0x14000ffc5a0, {0x1018b17a0, 0x1400017d8b0}, 0x140003e20f0)
	/Users/jmorgan/git/ollama/server/sched.go:472 +0x150
github.com/ollama/ollama/server.(*Scheduler).processPending(0x1400017d900, {0x1018b17a0, 0x1400017d8b0})
	/Users/jmorgan/git/ollama/server/sched.go:143 +0x3d0
github.com/ollama/ollama/server.(*Scheduler).Run.func1()
	/Users/jmorgan/git/ollama/server/sched.go:120 +0x28
created by github.com/ollama/ollama/server.(*Scheduler).Run in goroutine 1
	/Users/jmorgan/git/ollama/server/sched.go:119 +0xc4

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/4187 **Author:** [@jmorganca](https://github.com/jmorganca) **Created:** 5/6/2024 **Status:** ✅ Merged **Merged:** 5/6/2024 **Merged by:** [@jmorganca](https://github.com/jmorganca) **Base:** `main` ← **Head:** `jmorganca/unload-fix` --- ### 📝 Commits (1) - [`8a51d4a`](https://github.com/ollama/ollama/commit/8a51d4a367d9bb0d13fc3fddb23c0e26afc24138) unload in critical section ### 📊 Changes **2 files changed** (+7 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `server/sched.go` (+4 -4) 📝 `server/sched_test.go` (+3 -6) </details> ### 📄 Description While testing concurrency I noticed a segfault happen occasionally when loading, canceling, and loading the same model repeatedly over and over again with a script like this: ``` #!/bin/bash # Command to run COMMAND="ollama run llama3 hello" # Number of times to run the command concurrently N=100 # Running the command N times concurrently for i in $(seq 1 $N); do $COMMAND & done ``` The error looked like this: ``` panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x101298ae0] goroutine 51 [running]: github.com/ollama/ollama/server.(*runnerRef).needsReload(0x14000ffc5a0, {0x1018b17a0, 0x1400017d8b0}, 0x140003e20f0) /Users/jmorgan/git/ollama/server/sched.go:472 +0x150 github.com/ollama/ollama/server.(*Scheduler).processPending(0x1400017d900, {0x1018b17a0, 0x1400017d8b0}) /Users/jmorgan/git/ollama/server/sched.go:143 +0x3d0 github.com/ollama/ollama/server.(*Scheduler).Run.func1() /Users/jmorgan/git/ollama/server/sched.go:120 +0x28 created by github.com/ollama/ollama/server.(*Scheduler).Run in goroutine 1 /Users/jmorgan/git/ollama/server/sched.go:119 +0xc4 ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-22 21:59:36 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#37282