Repository navigation
fix(sqlite): await cleanup after startup failures - #4494
Open
samjingwen wants to merge 1 commit into
Open
samjingwen wants to merge 1 commit into
samjingwen wants to merge 1 commit into
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.
Does your PR solve an issue?
No existing issue is linked.
This fixes SQLite connection cleanup after startup errors in SQLx 0.9.0/current main.
SqliteConnectOptions::connect()establishes a worker before executing startup PRAGMAs and registering collations.If either step fails, dropping the connection does not wait for the worker to release its SQLite handle.
The caller can therefore receive an initialization error while the database connection is still being cleaned up.
Changes
close().Arcinto a raw pointer, avoiding a leaked reference when name validation fails.The regression calls the real
SqliteConnection::connect_with()API for invalid PRAGMAs, a corrupt database, and partially registered collations followed by an invalid name.It pauses the worker at an existing tracing boundary, verifies that error return remains pending while the worker still owns the connection, then checks a native SQLite destructor acknowledgement before accepting the returned error.
It also checks original-error preservation, unchanged corrupt-file contents, and release of both registered and rejected collation callbacks.
The test has its own binary because SQLite auto-extension registration is process-global, and unregisters only its own callback.
Is this a breaking change?
No public API or successful-connection behavior changes.
Startup error returns now wait for connection cleanup.
Normal successful connections retain their configured optimize-on-close behavior.
Cancellation/dropping of an in-flight connection future is not changed by this PR.
Verification
Local environment: macOS arm64, repository toolchain Rust 1.94.1,
libsqlite3-sys0.37.0, bundled SQLite 3.51.3.drop(conn).cargo fmt --all -- --checkpassed.cargo clippy -p sqlx-sqlite --all-targets --all-features -- -D warningspassed.cargo test -p sqlx-sqlite --all-featurespassed: 14 unit tests, the new regression, and 4 doc tests.sqlite,sqlite-types,sqlite-describe,sqlite-error,sqlite-migrate, andsqlite-derives.sqliteandsqlite-errorsuites passed under smol and async-global-executor: 50 tests per runtime.sqlitesuite retains its one pre-existing ignored test,issue_1467.Apple's built-in SQLite rejected auto-extension registration, so that library is not counted as passing this fixture.
Integration tests used disposable copies of the checked-in SQLite fixture, not retained application data.
CI and upstream review remain required before merging.