Fix SQLite cleanup with cached statements - #2549
Merged
an-tao merged 3 commits intoJul 29, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix SQLite connection cleanup when Drogon has cached prepared statements.
Sqlite3Connectionpreviously usedsqlite3_close()as the connection deleter. If cached prepared statements were still alive when the connection deleter ran, SQLite returnedSQLITE_BUSYand 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:
The test fails with the previous
sqlite3_close()behavior and passes withsqlite3_close_v2().Validation
SQLite3Test: 104 assertionsSQLite3TransactionTypeTest: 12 assertionsSQLite3TransactionTypeLockingTest: 1 assertionDbApiTest: 4 assertions