Fixes event loop blocking during file upload and document processing that causes liveness probe failures and pod restarts in Kubernetes deployments.
Problem
save_docs_to_vector_db() used asyncio.run() to call the async embedding function, which blocks the entire event loop. During large file uploads, this prevents uvicorn from responding to any requests (including health checks), causing Kubernetes to kill pods.
Additionally, CPU-bound text splitting operations (split_documents()) can block the event loop for extended periods on large files.
Solution
Convert save_docs_to_vector_db() and process_file() to async functions
Replace asyncio.run(embedding_function(...)) with await embedding_function(...)
Wrap CPU-bound text splitting in run_in_threadpool() to prevent blocking
Update all callers in files.py and retrieval.py to await the async functions, including the inner _process_handler function
Testing
I initially implemented this from branching off the v0.6.43 tag. I've been running this in our prod environment for about a week. It has been modified further due to changes on the dev branch to apply cleanly and account for upstream changes.
AI disclaimer
AI wrote some of this MR description and reviewed the code for this MR.
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 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/open-webui/open-webui/pull/20529
**Author:** [@jk-f5](https://github.com/jk-f5)
**Created:** 1/9/2026
**Status:** ❌ Closed
**Base:** `dev` ← **Head:** `fix/async-embedding-event-loop`
---
### 📝 Commits (1)
- [`fe6ff8d`](https://github.com/open-webui/open-webui/commit/fe6ff8d5193ca24c96353892ee31ed553b65cbe8) fix: prevent event loop blocking during file processing by converting to async
### 📊 Changes
**2 files changed** (+29 additions, -32 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/open_webui/routers/files.py` (+12 -12)
📝 `backend/open_webui/routers/retrieval.py` (+17 -20)
</details>
### 📄 Description
## Description
Fixes event loop blocking during file upload and document processing that causes liveness probe failures and pod restarts in Kubernetes deployments.
### Problem
`save_docs_to_vector_db()` used `asyncio.run()` to call the async embedding function, which blocks the entire event loop. During large file uploads, this prevents uvicorn from responding to any requests (including health checks), causing Kubernetes to kill pods.
Additionally, CPU-bound text splitting operations (`split_documents()`) can block the event loop for extended periods on large files.
### Solution
1. Convert `save_docs_to_vector_db()` and `process_file()` to async functions
2. Replace `asyncio.run(embedding_function(...))` with `await embedding_function(...)`
3. Wrap CPU-bound text splitting in `run_in_threadpool()` to prevent blocking
4. Update all callers in `files.py` and `retrieval.py` to await the async functions, including the inner `_process_handler` function
### Testing
I initially implemented this from branching off the v0.6.43 tag. I've been running this in our prod environment for about a week. It has been modified further due to changes on the dev branch to apply cleanly and account for upstream changes.
### AI disclaimer
AI wrote some of this MR description and reviewed the code for this MR.
### Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms.
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/20529
Author: @jk-f5
Created: 1/9/2026
Status: ❌ Closed
Base:
dev← Head:fix/async-embedding-event-loop📝 Commits (1)
fe6ff8dfix: prevent event loop blocking during file processing by converting to async📊 Changes
2 files changed (+29 additions, -32 deletions)
View changed files
📝
backend/open_webui/routers/files.py(+12 -12)📝
backend/open_webui/routers/retrieval.py(+17 -20)📄 Description
Description
Fixes event loop blocking during file upload and document processing that causes liveness probe failures and pod restarts in Kubernetes deployments.
Problem
save_docs_to_vector_db()usedasyncio.run()to call the async embedding function, which blocks the entire event loop. During large file uploads, this prevents uvicorn from responding to any requests (including health checks), causing Kubernetes to kill pods.Additionally, CPU-bound text splitting operations (
split_documents()) can block the event loop for extended periods on large files.Solution
save_docs_to_vector_db()andprocess_file()to async functionsasyncio.run(embedding_function(...))withawait embedding_function(...)run_in_threadpool()to prevent blockingfiles.pyandretrieval.pyto await the async functions, including the inner_process_handlerfunctionTesting
I initially implemented this from branching off the v0.6.43 tag. I've been running this in our prod environment for about a week. It has been modified further due to changes on the dev branch to apply cleanly and account for upstream changes.
AI disclaimer
AI wrote some of this MR description and reviewed the code for this MR.
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.