[PR #20528] [CLOSED] fix: prevent event loop blocking during file processing #112968

Closed
opened 2026-05-18 13:12:42 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/20528
Author: @jk-f5
Created: 1/9/2026
Status: Closed

Base: devHead: fix/async-embedding-event-loop


📝 Commits (1)

  • fe6ff8d fix: 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() 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.


🔄 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/20528 **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. --- <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-18 13:12:42 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#112968