⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@simolus3
Copy link
Contributor

Most SQLite libraries use sqlite3_close_v2 to close connections. That function is designed for garbage-collected languages where the database and prepared statements might not be freed in the correct order. So if a statement exists as the time sqlite3_close_v2 is called, the database is transitioned into a "zombie" state and resources are only fully released once prepared statements are closed as well.

The Rust sync client prepares statements to manage subscriptions and caches those statements across multiple powersync_control calls for efficiency. This causes issues if a database connection is closed while a sync iteration is active, since the database is transitioned into a zombie and we don't have an opportunity to free those statements. This might seem like a hypothetical scenario since all our SDKs would disconnect before closing connections, but our Dart sync tests are running into this and it's just not a good practice - closing the database should free everything.

As a workaround, this uses the xDisconnect callback SQLite runs in sqlite3_close_v2 (pretty much specifically for this type of issue) in one of our vtabs as a hook to drop the sync client when it runs. Because our virtual tables are scoped to the database schema, we can use this to detect that the database is about to be closed and free resources.

@simolus3 simolus3 requested a review from rkistner January 22, 2026 11:11
Copy link
Contributor

@rkistner rkistner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice - xDisconnect looks like a great trigger for this that I wasn't aware of.

@simolus3 simolus3 merged commit 40dbd6e into main Jan 22, 2026
25 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.

3 participants