mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-05 18:38:17 -05:00
[PR #20889] [CLOSED] fix: fix aiohttp session leak in streaming responses #41442
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/20889
Author: @Classic298
Created: 1/23/2026
Status: ❌ Closed
Base:
dev← Head:aiohttp📝 Commits (1)
cd515e6fix: fix aiohttp session leak in ollama router (#144)📊 Changes
2 files changed (+32 additions, -19 deletions)
View changed files
📝
backend/open_webui/routers/ollama.py(+17 -6)📝
backend/open_webui/routers/openai.py(+15 -13)📄 Description
Summary
Fixes "Unclosed client session" errors that occur when aiohttp sessions are not properly closed during streaming responses.
Root cause: BackgroundTask cleanup is unreliable - it doesn't execute when clients disconnect during streaming, causing session leaks that accumulate over time.
Solution: Replace BackgroundTask with a stream_wrapper async generator that guarantees cleanup in its finally block, which executes even when streaming is interrupted.
Changes
openai.py
ollama.py
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.