[PR #21158] [MERGED] fix: prevent worker death during document upload by using run_coroutine_threadsafe #25954

Closed
opened 2026-04-20 06:13:56 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/21158
Author: @Classic298
Created: 2/4/2026
Status: Merged
Merged: 2/12/2026
Merged by: @tjbck

Base: devHead: claude/fix-upload-process-issue-hcB7K


📝 Commits (2)

  • ea38916 fix: prevent worker death during document upload by using run_coroutine_threadsafe
  • 92f7f5c add env var

📊 Changes

2 files changed (+13 additions, -3 deletions)

View changed files

📝 backend/open_webui/main.py (+4 -0)
📝 backend/open_webui/routers/retrieval.py (+9 -3)

📄 Description

Best solution would be to fully propagate async/await the entire chain but this is a lot more work.

Replace asyncio.run() with asyncio.run_coroutine_threadsafe() in save_docs_to_vector_db() to prevent uvicorn worker health check failures.

The issue: asyncio.run() creates a new event loop and blocks the thread completely, preventing the worker from responding to health checks during long-running embedding operations (>5 seconds default timeout).

The fix: Schedule the async embedding work on the main event loop using run_coroutine_threadsafe(). This keeps the main loop responsive to health check pings while the sync caller waits for the result.

Changes:

  • main.py: Store main event loop reference in app.state.main_loop at startup
  • retrieval.py: Use run_coroutine_threadsafe() instead of asyncio.run()

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.

Note

Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.


🔄 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/21158 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 2/4/2026 **Status:** ✅ Merged **Merged:** 2/12/2026 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `claude/fix-upload-process-issue-hcB7K` --- ### 📝 Commits (2) - [`ea38916`](https://github.com/open-webui/open-webui/commit/ea38916ac56ac8205f892bc8a389477c5f14af73) fix: prevent worker death during document upload by using run_coroutine_threadsafe - [`92f7f5c`](https://github.com/open-webui/open-webui/commit/92f7f5cd21fb307d930bd41851d401dd052628c5) add env var ### 📊 Changes **2 files changed** (+13 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/main.py` (+4 -0) 📝 `backend/open_webui/routers/retrieval.py` (+9 -3) </details> ### 📄 Description Best solution would be to fully propagate async/await the entire chain but this is a lot more work. Replace asyncio.run() with asyncio.run_coroutine_threadsafe() in save_docs_to_vector_db() to prevent uvicorn worker health check failures. The issue: asyncio.run() creates a new event loop and blocks the thread completely, preventing the worker from responding to health checks during long-running embedding operations (>5 seconds default timeout). The fix: Schedule the async embedding work on the main event loop using run_coroutine_threadsafe(). This keeps the main loop responsive to health check pings while the sync caller waits for the result. Changes: - main.py: Store main event loop reference in app.state.main_loop at startup - retrieval.py: Use run_coroutine_threadsafe() instead of asyncio.run() ### 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. > [!NOTE] > Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in. --- <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-20 06:13:56 -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#25954