5-07-29 17:35:37,497 - ERROR - Unclosed client ses...
# ask-ai
a
2025-07-29 173537,497 - ERROR - Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x000002440D47B230> 2025-07-29 173537,498 - ERROR - Unclosed connector connections: ['deque([(<aiohttp.client_proto.ResponseHandler object at 0x000002440D4C0890>, 1300365.2458669)])'] connector: <aiohttp.connector.TCPConnector object at 0x000002440D47B380> Getting this error
t
Thanks for reaching out, giri. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The errors "Unclosed client session" and "Unclosed connector" in aiohttp typically occur when a session or connector is not properly closed after use. Here are some best practices and patterns to help resolve and prevent these issues: • Use Managed Sessions: Utilize utilities like
http_context.http_session()
to automatically manage and clean up sessions. For example:
Copy code
from livekit.agents.utils import http_context

# Get a managed session
session = http_context.http_session()
• Pass Sessions as Parameters: Instead of creating sessions internally, pass them as constructor parameters. This ensures better control and cleanup:
Copy code
def __init__(self, http_session: aiohttp.ClientSession | None = None):
    self._session = http_session
• Use Session Properties: Implement session properties with fallback to managed sessions:
Copy code
@property
def session(self) -> aiohttp.ClientSession:
    if not self._session:
        self._session = utils.http_context.http_session()
    return self._session
• Ensure Proper Cleanup: Always close WebSocket connections and sessions in
finally
blocks:
Copy code
finally:
    if ws is not None:
        await ws.close()
These practices should help address the errors you're encountering. If the issue persists, you may need to review your code for any instances where sessions or connectors are being created but not properly closed. Sources: livekit-plugins/livekit-plugins-lmnt/livekit/plugins/lmnt/tts.py