Skip to content

Commit 8e5025f

Browse files
committed
fix(toolbox-core): Prevent ToolboxClient from closing externally managed client sessions
This change ensures that the `ToolboxClient` only closes client sessions that it creates and manages internally. If a client session is provided externally (i.e., injected into the `ToolboxClient`), the responsibility for managing its lifecycle, including closing it, remains with the entity that provided it. This prevents unintended closure of externally managed sessions.
1 parent 536ec0a commit 8e5025f

File tree

1 file changed

+5
-1
lines changed
  • packages/toolbox-core/src/toolbox_core

1 file changed

+5
-1
lines changed

packages/toolbox-core/src/toolbox_core/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class ToolboxClient:
3333

3434
__base_url: str
3535
__session: ClientSession
36+
__manage_session: bool
3637

3738
def __init__(
3839
self,
@@ -56,7 +57,9 @@ def __init__(
5657
self.__base_url = url
5758

5859
# If no aiohttp.ClientSession is provided, make our own
60+
self.__manage_session = False
5961
if session is None:
62+
self.__manage_session = True
6063
session = ClientSession()
6164
self.__session = session
6265

@@ -145,7 +148,8 @@ async def close(self):
145148
is responsible for its lifecycle, but calling close here will still
146149
attempt to close it.
147150
"""
148-
await self.__session.close()
151+
if self.__manage_session:
152+
await self.__session.close()
149153

150154
async def load_tool(
151155
self,

0 commit comments

Comments
 (0)