[PR #16016] [CLOSED] fix: issue: Using an external tool server causes the response to be unable to stop #15695 #24005

Closed
opened 2026-04-20 05:10:45 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/16016
Author: @Godzilla675
Created: 7/25/2025
Status: Closed

Base: mainHead: main


📝 Commits (8)

  • 9b8e8ad Initial plan
  • 5b49c1e Initial plan
  • 79a0458 Fix unclosed aiohttp client sessions when stopping tool tasks
  • 58f2c7f Fix unclosed client session errors during tool execution cancellation
  • f3287a8 Merge pull request #1 from Godzilla675/copilot/fix-1342ccd3-cd80-4505-ae44-1bf76a649439
  • adc5086 Revert "Fix unclosed client session errors during tool execution cancellation"
  • fe1c3a2 Merge pull request #4 from Godzilla675/revert-1-copilot/fix-1342ccd3-cd80-4505-ae44-1bf76a649439
  • 6ff571f Merge pull request #3 from Godzilla675/copilot/fix-f7ce3b69-3e20-4a60-8c49-0c4395d3ca09

📊 Changes

1 file changed (+27 additions, -3 deletions)

View changed files

📝 backend/open_webui/utils/tools.py (+27 -3)

📄 Description

Before submitting, make sure you've checked the following:

Target branch: Please verify that the pull request targets the dev branch.
Description: Provide a concise description of the changes made in this pull request.
Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
Testing: Have you written and run sufficient tests to validate the changes?
Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following: fix (Bug fix or error correction)
Problem
When users clicked the stop button during tool execution in chat completions, the backend would log "Unclosed client session" and "Unclosed connector" warnings. This issue only occurred when tools were involved in the generation process.

Root Cause
The problem was in the execute_tool_server() and get_tool_server_data() functions in /backend/open_webui/utils/tools.py. These functions used the async with aiohttp.ClientSession() pattern, but when tasks containing these functions were cancelled via the stop button, the session cleanup might not complete properly during cancellation.

Solution
Modified both functions to ensure proper session cleanup even when tasks are cancelled by implementing manual session management with explicit cleanup in try/finally blocks and dedicated asyncio.CancelledError handlers.

Changelog Entry
Description
Fixed unclosed aiohttp client sessions when stopping tool tasks, eliminating resource leaks and "Unclosed client session" warnings that occurred when users cancelled tool execution mid-process.

Added
Explicit asyncio.CancelledError handling in tool server functions
Informative logging when tool operations are cancelled
Changed
Modified execute_tool_server() to use manual session management with defensive cleanup
Modified get_tool_server_data() to use manual session management with defensive cleanup
Replaced async with aiohttp.ClientSession() pattern with explicit session creation and cleanup
Fixed
Resource leak: Unclosed aiohttp client sessions when tasks are cancelled
Warning messages: "Unclosed client session" and "Unclosed connector" errors in logs
Session cleanup: Proper session closure during task cancellation scenarios
Additional Information
This fix ensures HTTP sessions are properly closed in all scenarios: normal completion, error conditions, and task cancellation
No breaking changes - all existing tool execution behavior is preserved
Affects only the backend tool execution infrastructure
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/16016 **Author:** [@Godzilla675](https://github.com/Godzilla675) **Created:** 7/25/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (8) - [`9b8e8ad`](https://github.com/open-webui/open-webui/commit/9b8e8ad0db2a6b1f6e45789aea89a240d8741add) Initial plan - [`5b49c1e`](https://github.com/open-webui/open-webui/commit/5b49c1ee6cb7c7c3ace57107adbc70ac5a9e23b7) Initial plan - [`79a0458`](https://github.com/open-webui/open-webui/commit/79a0458a78ef91b2680386de78879a28482e7a91) Fix unclosed aiohttp client sessions when stopping tool tasks - [`58f2c7f`](https://github.com/open-webui/open-webui/commit/58f2c7fefd74fb3a340fdb0a0f4cde20e3455426) Fix unclosed client session errors during tool execution cancellation - [`f3287a8`](https://github.com/open-webui/open-webui/commit/f3287a8d1260b61038cd26709b408f71bff2d520) Merge pull request #1 from Godzilla675/copilot/fix-1342ccd3-cd80-4505-ae44-1bf76a649439 - [`adc5086`](https://github.com/open-webui/open-webui/commit/adc508622c44741cd16a20f81ffa7b10daa041e3) Revert "Fix unclosed client session errors during tool execution cancellation" - [`fe1c3a2`](https://github.com/open-webui/open-webui/commit/fe1c3a2f8f8e31ed2e60f238c3b82fa3f6f2f2dd) Merge pull request #4 from Godzilla675/revert-1-copilot/fix-1342ccd3-cd80-4505-ae44-1bf76a649439 - [`6ff571f`](https://github.com/open-webui/open-webui/commit/6ff571fa05d5715e1676b2820409eae952689346) Merge pull request #3 from Godzilla675/copilot/fix-f7ce3b69-3e20-4a60-8c49-0c4395d3ca09 ### 📊 Changes **1 file changed** (+27 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/utils/tools.py` (+27 -3) </details> ### 📄 Description Before submitting, make sure you've checked the following: Target branch: Please verify that the pull request targets the dev branch. Description: Provide a concise description of the changes made in this pull request. Changelog: Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. Documentation: Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources? Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation? Testing: Have you written and run sufficient tests to validate the changes? Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following: fix (Bug fix or error correction) Problem When users clicked the stop button during tool execution in chat completions, the backend would log "Unclosed client session" and "Unclosed connector" warnings. This issue only occurred when tools were involved in the generation process. Root Cause The problem was in the execute_tool_server() and get_tool_server_data() functions in /backend/open_webui/utils/tools.py. These functions used the async with aiohttp.ClientSession() pattern, but when tasks containing these functions were cancelled via the stop button, the session cleanup might not complete properly during cancellation. Solution Modified both functions to ensure proper session cleanup even when tasks are cancelled by implementing manual session management with explicit cleanup in try/finally blocks and dedicated asyncio.CancelledError handlers. Changelog Entry Description Fixed unclosed aiohttp client sessions when stopping tool tasks, eliminating resource leaks and "Unclosed client session" warnings that occurred when users cancelled tool execution mid-process. Added Explicit asyncio.CancelledError handling in tool server functions Informative logging when tool operations are cancelled Changed Modified execute_tool_server() to use manual session management with defensive cleanup Modified get_tool_server_data() to use manual session management with defensive cleanup Replaced async with aiohttp.ClientSession() pattern with explicit session creation and cleanup Fixed Resource leak: Unclosed aiohttp client sessions when tasks are cancelled Warning messages: "Unclosed client session" and "Unclosed connector" errors in logs Session cleanup: Proper session closure during task cancellation scenarios Additional Information This fix ensures HTTP sessions are properly closed in all scenarios: normal completion, error conditions, and task cancellation No breaking changes - all existing tool execution behavior is preserved Affects only the backend tool execution infrastructure 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/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>
GiteaMirror added the pull-request label 2026-04-20 05:10:45 -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#24005