Repository navigation
Conversation
…onger frees the result in use `dbFetch()` on a statement raises a warning from C++, and a calling handler that cleared the result freed the object that the fetch still used. A result now counts as busy while one of its fetches or binds runs, and `dbClearResult()` refuses a busy result with an error, so the handler sees the error and the fetch returns its empty data frame. Closes #601. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
…R callback Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
Accepted limitationsThe clean review found nothing above Low in this change. Its three Lows are fixed in c2d9b13: the messages now name any R callback rather than only warning handlers,
Generated by Claude Code |
|
Rethink an alternative: queue and raise the warning just before returning to R. |
|
Working on it, as an alternative PR from The same idea may also cover the interrupt check in the fetch loop (#621, fixed in #629 with the busy flag from this PR): detect a pending interrupt without running handlers, stop the fetch cleanly, and let R handle the interrupt after returning. That is being investigated. If it works, #611, the busy-check part of #624 and #629 could all be replaced; I'll say which ones once the alternative has been reviewed. Generated by Claude Code |
|
The alternative is up as draft #632: warnings are queued and raised after the C++ work, so a warning handler can call Generated by Claude Code |
|
The alternative is preferred, closing. |
…632) * fix: Raise warnings only after the C++ code is done with the result Closes #601. Warnings raised while C++ code holds a result or a connection are queued and signaled by the entry points just before returning to R, so that a calling handler can no longer free the result or close the connection under our feet. The warning about cancelling the previous query is raised before the new result is created, and destructors only queue. This is an alternative to #611, which refuses dbClearResult() from such a handler. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ * chore: Auto-update from GitHub Actions Run: https://github.com/r-dbi/RMariaDB/actions/runs/46270935930 * fix: Raise warnings from destructors at top level, not in an unrelated call The warning for a connection collected by gc() went into the same queue as the warnings of the current call, and surfaced in the next call on any connection. With options(warn = 2), it turned a healthy call into an error and lost its result. Destructors now queue into a separate queue. A task callback registered in .onLoad() drains it after each top-level call, and R prints its warnings after the output of that call. An error from the callback, e.g. with options(warn = 2), is printed and keeps the callback registered. The tests ignore unrelated warnings. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ * fix: Drop warnings left by a failed call at the start of the next one A call that queued a warning and then failed never signaled it, so the warning surfaced in a later, unrelated call. Each entry point that signals queued warnings now clears the queue first. A warning that preceded an error is dropped, the error is what matters. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ * fix: Release a new result when raising its warnings fails With options(warn = 2) or an exiting warning handler, dbSendQuery() never returned the new result, which stayed the connection's current result until garbage collection. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ * fix: Register the warning callback by name, and raise leak warnings in `dbConnect()` too Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ * refactor: Raise leak warnings at the start of the next call instead of from a task callback Drop the top-level task callback. Warnings queued by destructors during garbage collection are now raised at the start of the next call into the library (result_create(), result_fetch(), result_bind(), connection_create()), before any C++ work, so that an error under options(warn = 2) leaves no state changed and no result lost. The leak warning text says that the connection may stem from an earlier operation. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ * fix: Keep the destructor from throwing, and restore a signature's formatting Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ --------- Co-authored-by: Claude <[email protected]>
Closes #601.
Before this change, a warning that
dbFetch()raised ran R's calling handlers while the C++ fetch was still on the stack. A handler that calleddbClearResult()deleted the result, and the fetch then read freed memory. Valgrind reported invalid reads, and the session could crash.Change
DbResult::fetch()andDbResult::bind()now run throughrun_guarded(), ported from RSQLite (fix: Never restart a statement after an error indbFetch()ordbBind()RSQLite#830). It sets a busy flag and usesR_ExecWithCleanup(), so the flag is reset even when the call ends with an R error.DbResult::busy()exposes the flag. While it is set,dbClearResult()fails with "Can't clear a result while one of its fetches or binds is running, as from R code that it calls, such as a condition handler.". A nesteddbFetch()ordbBind()from such R code is refused with a similar message.immediate = TRUEresults (which raise the same warning), and any R callback during a bind.src/MariaRow.*andsrc/MariaResultPrep.*are not touched, since feat: ALTREP-backeddbFetch()with storage-aware column types #587 rewrites them.Tests
tests/testthat/test-dbClearResult.R(new) checks the error messages fordbClearResult()and for a nesteddbFetch()anddbBind(), that the fetch returns an empty result, and that the result stays valid and can be cleared afterwards. Under valgrind, the issue's reproducer gives invalid reads and then a segfault onmain, and 0 errors with this change, for both the prepared and theimmediate = TRUEpath. Local run against MariaDB 10.11 withNOT_CRAN=true: the whole suite had 0 failures and the onetest-timezone.Rerror ("US/Alaska" unknown to CCTZ in this container), which also happens onmain. MySQL was not tested: there is no server in this container, and CI's MySQL entries currently run MariaDB (#592).Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
Generated by Claude Code