Issue: SQLite Connection Never Closed in Games Cog
Location
cog/games.py lines 9-13 and cog/games.py lines 699-703
Problem
The GamesDatabase class opens a SQLite connection at initialization that is never explicitly closed:
class GamesDatabase():
def __init__(self, db_name: str = DB_PATH):
self.conn = sqlite3.connect(db_name)
self.conn.execute("PRAGMA foreign_keys = 1")
self._init_db()
# No close() method!
class Games(commands.Cog):
def __init__(self, bot):
self.db = GamesDatabase() # Connection opened at cog load
# No cog_unload to close!
Impact
- Resource leak: Connection held for entire bot lifetime
- Connection pool exhaustion if cog is reloaded multiple times
- Potential database corruption on restart if connections aren't properly released
Recommended Fix
Add proper cleanup:
class GamesDatabase():
def __init__(self, db_name: str = DB_PATH):
self.conn = sqlite3.connect(db_name, timeout=30)
self.conn.execute("PRAGMA foreign_keys = 1")
self._init_db()
def close(self):
if self.conn:
self.conn.close()
class Games(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.bot_user = bot.user
self.db = GamesDatabase()
def cog_unload(self):
self.db.close()
Note: Consider using aiosqlite for async-compatible database operations as well.
Severity
High - Resource leak on cog reload
Issue: SQLite Connection Never Closed in Games Cog
Location
cog/games.pylines 9-13 andcog/games.pylines 699-703Problem
The
GamesDatabaseclass opens a SQLite connection at initialization that is never explicitly closed:Impact
Recommended Fix
Add proper cleanup:
Note: Consider using
aiosqlitefor async-compatible database operations as well.Severity
High - Resource leak on cog reload