Repository navigation
fix: A fetch stops cleanly when R code it calls closes its result or connection - #629
Conversation
Superseded: Accepted limitationsThe clean review found nothing above Low. The reviewer confirmed that
Generated by Claude Code |
|
Same remedy as proposed for #615 possible? |
|
Yes, I think so. Instead of refusing a query or Generated by Claude Code |
7dcc9cc to
50c2cb1
Compare
dbDisconnect() while a result of the connection is being fetched
Superseded by the question below: R code from an interrupt handler that uses the result being fetchedWith #632, warnings no longer run R code during a fetch, but the interrupt check in the fetch loop still does. A query or
Both need a handler that resumes after an interrupt and uses that very result.
If nobody decides, I'll implement the first option in a PR stacked on this one. Generated by Claude Code |
Accepted limitationsThis is for the version rebuilt without #611's busy flag. Its clean review found nothing above Low. Under valgrind, the interrupt reproducer ends in the new error with 0 errors, for a query and for Two Lows are fixed in 126b5b3:
Generated by Claude Code |
|
If released memory is the problem, can't we take ownership of all objects that we need to be alive and/or avoid reentrancy or destruction by setting a guard? The current solution looks like a lot of complexity for an edge case, also willing to go with declaring this limitation. Resolve conflicts. |
|
The conflicts are resolved: #624 has the latest Resolved: Guard, or declare the limitation?Resolved by the merge of this PR on 2026-11-29: the post-check stays as it is. The memory at stake is the
If nobody decides, I'll go with the first option. Generated by Claude Code |
…connection Closes #621. An interrupt handler that resumes can run a query or `dbDisconnect()` during `dbFetch()`, which closes the result being fetched as usual. After each interrupt check, the fetch now checks that its statement is still open, and fails with a clear error instead of reading the freed statement. The same check follows the metadata update of a further parameter set, which can warn. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
…gnal misses Call result_fetch() directly after the signal so that R handles the interrupt inside the fetch loop, and skip() if no attempt hits it. Drop the check_open() after update_metadata() in step(): the only callback there is the type warning. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
6e17a99 to
ce0bbc5
Compare
Closes #621. Stacked on #624.
Before this change, R code that ran during a fetch could run a query or call
dbDisconnect()on the same connection, and R then crashed or read freed memory. The fetch loop checks for interrupts every 1024 rows, so an interrupt handler that resumes is one way in. Rebuilt as you suggested, with the same remedy as #615 and without #611's busy flag.Change
dbDisconnect()from such R code is no longer refused. It closes the result or the connection as usual, which sets the result's statement toNULL. The C++ result object stays alive, because R holds it.MariaResultPrep::check_open()runs right aftercpp11::check_user_interrupt()in the fetch loop. If the statement or the connection has been closed, it stops with "The result was closed while it was being fetched." before any closed state is used.Not covered:
dbClearResult()on the result being fetched, from an interrupt handler. That call deletes the C++ object itself, not just its statement; see the question below.Tests
tests/testthat/test-dbDisconnect.Rgains a test that sends an interrupt to its own process just before calling the C++ fetch on a 10,000-row cross join. The interrupt handler runs a query ordbDisconnect()and resumes. The test then expects the new error and an invalid result. The interrupt lands inside the fetch on the first attempt in 49 of 50 runs. The test retries up to 10 times, and skips with a clear message if every attempt misses. It is skipped on CRAN and Windows. Without the fix, it crashes R.Under valgrind, the issue's interrupt reproducer ends in the new error with 0 errors, for
MODE=sendandMODE=disc, with both MariaDB Connector/C 3.3.17 and libmysqlclient 8.0.46. Local runs against MariaDB 10.11 withNOT_CRAN=true: the whole suite had 0 failures with both client libraries, apart from thetest-timezone.R"US/Alaska" error, which comes from this container. MySQL servers were 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
https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
Generated by Claude Code