Repository navigation
Conversation
…inds runs A calling handler of a warning raised by `dbFetch()` or `dbColumnInfo()`, or a busy handler called while a fetch or `dbBind()` steps, runs R code while the C++ code of the result is on the stack. When such a handler called `dbClearResult()` on that result, the result and its statement were freed under that code, and R crashed when the fetch went on. A result is now marked busy while one of its fetches or binds runs, or while `dbColumnInfo()` reads its first row. `dbClearResult()` on a busy result fails and leaves the result as it is. A fetch, a bind or `dbColumnInfo()` of a busy result fails too, and so does a new query on its connection, because it clears the open result first. The mark is released on every exit path, also when an R error longjmps past the C++ frames, through `R_ExecWithCleanup()`. The warning of a fetch from a statement that is no query is raised through cpp11, so that an error made of it unwinds the C++ frames. The tests run the handlers in a callr session, because the unguarded code crashes R. Ported from #830 (ae87b09, and the warning change of 1d0d70f). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
…claude/rb-busy-guard Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
`result_release()` refused a busy result with `cpp11::stop()`. With cpp11 before 0.4.6, that error, raised from a handler during a fetch, could longjmp past the C++ destructors of the fetch. It now throws a `std::runtime_error`, as `run_guarded()` does, which the cpp11 entry point turns into an R error. Both refusal messages now name what they refuse, including a new query on the connection, and both causes, a warning handler or a busy handler. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
… query Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
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.
A calling handler of a warning that
dbFetch()ordbColumnInfo()raises, or a busy handler that SQLite calls while a fetch ordbBind()steps, runs R code while the C++ code of the result is on the stack. When such a handler calleddbClearResult()on that result, the result and its statement were freed under the running code: R crashed when the fetch went on (for example afterinvokeRestart("muffleWarning")), and a fetch, bind ordbColumnInfo()of the same result from the handler stepped the statement under the running fetch, so the outer fetch lost rows anddbGetRowCount()counted wrong.What changes for users: a result is marked busy while one of its fetches or binds runs, or while
dbColumnInfo()reads its first row.dbClearResult()on a busy result fails with "Can't clear a result, or send a query on its connection, while one of its fetches or binds is running, as from a warning or busy handler." and leaves the result as it is. A fetch, a bind ordbColumnInfo()of a busy result fails with "Can't fetch from or bind to a result, or read its column info, while one of its fetches or binds is running, …". A new query on the same connection from such a handler fails with the first message, becausedbSendQuery()clears the connection's open result first. Exiting handlers (tryCatch()),on.exit(dbClearResult(res))and garbage collection work as before. The mark is released on every exit path, also when an R error longjmps past the C++ frames, throughR_ExecWithCleanup(); C++ exceptions are caught inside the guarded body and rethrown after it, so none crosses R's C frames. The warning for a fetch from a statement that is no query is now raised throughcpp11::warning(), so that an error made of it (for example underoptions(warn = 2)) unwinds the C++ frames instead of longjmping past them; its condition call is nowNULLinstead ofresult_fetch(res@ptr, n = n).What this layer does not change: an error that leaves a fetch still leaves the result where it was (layer B4 completes it), and a failed bind keeps its state (layer B5).
Tests: eight new tests in
tests/testthat/test-dbClearResult.R. Seven run the handler in acallrsession, because the unguarded code crashes R, and skip unless that session loads the RSQLite under test (tests/testthat/helper-callr.Rfrom #830, now withskip_if_not_installed("callr")). On the base branch all seven fail: four because the session crashes (muffled fetch warning,dbColumnInfo()warning, busy handler duringdbBind(), re-entrant fetch/bind/column info/new query), and three becausedbClearResult()freed the result without an error, so it was no longer valid afterwards. With this change they pass. The eighth test, in process, pins that a result can be cleared once its fetch is left, by an exiting handler or by an error underoptions(warn = 2). Full suite withNOT_CRAN=true: FAIL 0, WARN 3 (locale), SKIP 63, PASS 10820.Layer B3 of the rebuilt chain, planned in #880; based on #933. Ported from #830 (now a draft): commit ae87b09 (
run_guarded(),result_release()refusing a busy result), theRf_warning()→cpp11::warning()change of 1d0d70f, andhelper-callr.R; the guard and its messages are those of #795 without its Arrow and thread parts. #830's open question on the wording of the busy guard's message for a handler that sends a new query applies here unchanged, since this layer introduces that message.Coordinating session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Generated by Claude Code