From af3533a0732afbada2ee32210aa1c5d1fe56a78b Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Mar 2026 14:14:00 +0000 Subject: [PATCH] fix: use force_close=True on TCPConnector to prevent stale connection errors The aiohttp ClientSession was created once at startup and its connection pool would accumulate stale connections that were closed by the server or network. When the next movie request tried to reuse a stale connection it failed with "the connection is closed", surfaced to users as "Failed to create movie on Ombi: the connection is closed". Using TCPConnector(force_close=True) ensures connections are never reused from the pool, so each request gets a fresh connection. https://claude.ai/code/session_01SYC6X4KRLv3r3RpwvRSLQu --- .../app/core/management/commands/start_discord_bot.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/django-app/app/core/management/commands/start_discord_bot.py b/packages/django-app/app/core/management/commands/start_discord_bot.py index 4555297..2a7989b 100644 --- a/packages/django-app/app/core/management/commands/start_discord_bot.py +++ b/packages/django-app/app/core/management/commands/start_discord_bot.py @@ -1,5 +1,6 @@ import asyncio +import aiohttp from aiohttp import ClientSession from discord.ext import commands from discordbot.bot import OscarrBot @@ -8,7 +9,8 @@ async def run(): - async with ClientSession() as web_client: + connector = aiohttp.TCPConnector(force_close=True) + async with ClientSession(connector=connector) as web_client: async with OscarrBot( commands.when_mentioned, web_client=web_client,