Skip to content

Fix SQLite cleanup with cached statements - #2549

Merged
an-tao merged 3 commits into
drogonframework:masterfrom
mcirsta:bugfix/sqlite-disconnect-leak
Jul 29, 2026
Merged

Fix SQLite cleanup with cached statements#2549
an-tao merged 3 commits into
drogonframework:masterfrom
mcirsta:bugfix/sqlite-disconnect-leak

Conversation

@mcirsta

@mcirsta mcirsta commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix SQLite connection cleanup when Drogon has cached prepared statements.

Sqlite3Connection previously used sqlite3_close() as the connection deleter. If cached prepared statements were still alive when the connection deleter ran, SQLite returned SQLITE_BUSY and left the connection open. The return value was ignored, and no later close attempt was made after the statements were finalized, causing the SQLite connection and related allocations to leak.

This changes the deleter to sqlite3_close_v2(). It marks the connection for deferred destruction, allowing SQLite to release it automatically after the final cached statement has been finalized.

Regression test

The new test:

  1. Initializes Drogon and SQLite without creating a cached statement.
  2. Records SQLite's memory usage.
  3. Creates another client and executes a parameterized query, which enters Drogon's statement cache.
  4. Disconnects the client and verifies that SQLite did not retain additional memory.

The test fails with the previous sqlite3_close() behavior and passes with sqlite3_close_v2().

Validation

  • Formatted with clang-format 17.0.6
  • Debug build with AddressSanitizer
  • Full registered test suite: 143/143 passed
  • Regression test passed 20 consecutive runs with LeakSanitizer enabled
  • Existing SQLite ORM test groups passed:
    • SQLite3Test: 104 assertions
    • SQLite3TransactionTypeTest: 12 assertions
    • SQLite3TransactionTypeLockingTest: 1 assertion
    • DbApiTest: 4 assertions

@an-tao
an-tao merged commit 00b71f9 into drogonframework:master Jul 29, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants