Skip to content

[HIGH] Synchronous SQLite in Async Context #48

Description

@galpt

🟠 High: Synchronous SQLite in Async Context

Problem Description

All sqlite3 operations use sqlite3.connect() which is a synchronous, blocking API. These are called within async functions without using asyncio.to_thread().

GamesDatabase (cog/games.py)

# cog/games.py line 11
self.conn = sqlite3.connect(db_name)  # Shared sync connection

Reminder Database (cog/reminder.py)

Multiple sqlite3.connect() calls throughout worker loop.

Exact Location

  • File: cog/games.py lines 9-43, 824-826
  • File: cog/reminder.py lines 339, 441, 654, 669, 741, 756, 773

Impact

  • Blocking the event loop causes command processing delays
  • Potential timeouts under load
  • "database locked" errors during concurrent game sessions

Recommended Fix

Wrap blocking calls with asyncio.to_thread():

await asyncio.to_thread(self.db.update_stats, user_id, result, game, bot_user_id)

Or migrate to aiosqlite (already in requirements.txt but unused).

Severity

HIGH — Event loop blocking causes responsiveness issues.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions