Repository navigation
Conversation
connection_connect() tags the external pointer with `RSQLite_connection`, and every entry point that takes a connection checks the tag, as result pointers do since #937. A pointer that isn't a connection's fails with "Invalid connection" instead of being read as one, which let connection_release() disconnect a result's connection. connection_valid() and connection_release() keep treating a pointer that holds NULL as closed, with or without the tag; the other entry points fail for it instead of crashing R. sqliteIsTransacting() and sqliteCopyDatabase() from a disconnected connection fail with "Invalid or closed connection" instead of passing a NULL handle to SQLite and crashing R. Closes #938. Closes #939. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
A connection pointer that holds NULL fails with "Invalid or closed connection" before the tag is checked, as connection_valid() does, so that a connection saved by RSQLite 3.54.1 or earlier fails as NEWS describes. DbConnection::conn() fails with the same message instead of "disconnected", which covers initExtension() and sqliteCopyDatabase() to a disconnected connection. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
…finish the copy `sqlite3_backup_init()` returns `NULL` when it can't start the copy, for instance for the same connection as source and destination, and the copy dereferenced it and crashed R. It now fails with SQLite's error from the destination, such as "source and destination must be distinct". A copy step that fails now finishes the backup, which releases the backup and its write lock on the destination. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
This was referenced Dec 1, 2026
This branch has not been deployed
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.
sqliteIsTransacting()on a disconnected connection, andsqliteCopyDatabase()from one, now fail with "Invalid or closed connection" instead of crashing R. A connection that was saved and restored fails the same way instead of with "bad_weak_ptr", also one saved by RSQLite 3.54.1 or earlier (without the tag) or made withnew("SQLiteConnection").initExtension()on a disconnected connection, andsqliteCopyDatabase()to one, fail the same way instead of with "disconnected".dbIsValid()anddbDisconnect()keep their behavior for both (FALSE, andTRUEwith the "Already disconnected" warning).The internal entry points that take a connection read any external pointer as one: given a result's pointer,
connection_valid()returnedTRUEandconnection_release()disconnected the result's connection, and given a pointer that holdsNULL,connection_in_transaction()andconnection_copy_database()crashed R.connection_connect()now tags the pointer with the symbolRSQLite_connection, the same design as the result tag of #937. The functions that need a live connection (connection_in_transaction(),connection_limit_length(),connection_copy_database(),connection_import_file(),set_busy_handler(),extension_load(),result_create()) now takeDbConnectionPtr*through anas_cpp()specialization inRSQLite_types.hthat checks the address ("Invalid or closed connection", with or without the tag, asconnection_valid()does) and then the tag ("Invalid connection"); this replaces an unusedas_cpp()inconnection.cppthat said "Invalid result set".connection_valid()andconnection_release()treat a pointer that holdsNULLas closed, with or without the tag, and check the tag otherwise, likeresult_valid()andresult_release()in #937.DbConnection::in_transaction()andDbConnection::copy_to()now callcheck_connection(): they passed theNULLhandle of a closed connection to SQLite.DbConnection::conn()calls it too, instead of failing with "disconnected".sqliteCopyDatabase()with the same connection as source and destination crashed R (also in RSQLite 3.54.1):sqlite3_backup_init()returnsNULLandcopy_to()dereferenced it. It now fails with SQLite's error from the destination, "Could not start copy:\nsource and destination must be distinct". A failed copy step now callssqlite3_backup_finish(), which releases the backup and its write lock on the destination; before, another connection could not write to the destination. This fix is ported down from #943, which raises the same errors as classed conditions.Tests: the new tests in
test-dbConnect.R,test-transactions.Randtest-sqliteCopyDatabase.Rrun the calls that could crash in a callr session. On the base branch, the three callr tests fail because the session crashes, and the two in-process tests fail with "bad_weak_ptr"; with this change all pass. Two in-process tests intest-sqliteCopyDatabase.Rcover the copy: the same-connection copy crashes a callr session on the base branch and fails with the error above with this change; a copy into a WAL database with a different page size fails after locking the destination, and on the base branch a second connection then fails to write to the destination with "database is locked", while with this change it writes and the source and destination stay usable. Full suite withNOT_CRAN=true: FAIL 0, WARN 3 (locale), SKIP 63, PASS 11060.The crash of #940 (a busy handler that clears the result whose bind waits for the lock) is fixed by #934: the reprex from #940 ends with "database is locked" on the base branch instead of a segfault, and #934's test "a busy handler can't clear the result whose bind waits for it" in
test-dbClearResult.Rcovers that case, so this PR adds no test for it. The other items of #940 (a handler that disconnects its own connection, documentation) remain open.Layer B7 of the rebuilt chain, planned in #880; based on #937. New in the rebuilt chain, not ported from an old PR.
Closes #938.
Closes #939.
Coordinating session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Generated by Claude Code