Hi, so to be short i have a discord bot that constantly sends requests to an API, but every once in a while aiohttp raises a aiohttp.ConnectionTimeoutError, followed by an asyncio.CancelledError. I would not make to much of an issue about that but after it happens something strange start happening, and the bot (i'm using pycord) stops working.
This issue is occurring in production enviroment (since i never made him run locally for large amount of times, now it is online 24/7), initially it happened every 24 hours more or less, to try to solve it i added a custom session:
import aiohttp
_session: aiohttp.ClientSession | None = None
def get_session() -> aiohttp.ClientSession:
global _session
if _session and not _session.closed:
return _session
timeout = aiohttp.ClientTimeout(total=30, connect=10, sock_connect=10, sock_read=20)
connector = aiohttp.TCPConnector(limit=100, ttl_dns_cache=300)
_session = aiohttp.ClientSession(timeout=timeout, connector=connector)
return _session
async def close_session():
global _session
if _session and not _session.closed:
await _session.close()
_session = None
This change seems to work just fine but today the issue appeared again after 5 bot working days
Here you can find the logs: https://pastebin.com/d4E52uEL
After this error occurs it seems like my main loop gots blocked, i can't invoke commands and no errors are shown when i do, the bot responds with interaction error like if the bot is offline, even if so i still got logs from background activities like scheduled cogs and tasks
(More or less the bot sends 80+ request per hour)
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.