[PR #10541] [MERGED] ggml: Fix race that resulted in "context canceled" when loading #75565

Closed
opened 2026-05-05 07:59:10 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/10541
Author: @jessegross
Created: 5/2/2025
Status: Merged
Merged: 5/2/2025
Merged by: @jessegross

Base: mainHead: jessegross/canceled


📝 Commits (1)

  • fcbb2d9 ggml: Fix race that resulted in "context canceled" when loading

📊 Changes

1 file changed (+5 additions, -8 deletions)

View changed files

📝 ml/backend/ggml/ggml.go (+5 -8)

📄 Description

Successfully completing processing with an errgroup cancels the associated context. However, we also have a goroutine that is checking for cancelation of the context. As a result, there is a race where the goroutine can pick up the cancelation and report an error, replacing the sucessful error message.

To avoid that, this replaces the goroutine with a cancelation check when we are reading files. This also has the advantage of stopping all reads relatively quickly on error and also ensuring that there are no outstanding I/O operations when we return in this case.

The downside is that if a file read blocks forever (for example, over the network) then cancelation of the context effectively won't be honored. However, this is also true for other smaller files we read and the tensors are read in small chunks (128K), so it's consistent and better on balance overall.


🔄 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/10541 **Author:** [@jessegross](https://github.com/jessegross) **Created:** 5/2/2025 **Status:** ✅ Merged **Merged:** 5/2/2025 **Merged by:** [@jessegross](https://github.com/jessegross) **Base:** `main` ← **Head:** `jessegross/canceled` --- ### 📝 Commits (1) - [`fcbb2d9`](https://github.com/ollama/ollama/commit/fcbb2d93481092f1b35b8a04300dc439a17b7cd2) ggml: Fix race that resulted in "context canceled" when loading ### 📊 Changes **1 file changed** (+5 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `ml/backend/ggml/ggml.go` (+5 -8) </details> ### 📄 Description Successfully completing processing with an errgroup cancels the associated context. However, we also have a goroutine that is checking for cancelation of the context. As a result, there is a race where the goroutine can pick up the cancelation and report an error, replacing the sucessful error message. To avoid that, this replaces the goroutine with a cancelation check when we are reading files. This also has the advantage of stopping all reads relatively quickly on error and also ensuring that there are no outstanding I/O operations when we return in this case. The downside is that if a file read blocks forever (for example, over the network) then cancelation of the context effectively won't be honored. However, this is also true for other smaller files we read and the tensors are read in small chunks (128K), so it's consistent and better on balance overall. --- <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-05-05 07:59:10 -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#75565