Repository navigation
fix: Results of a closed connection fail cleanly instead of crashing - #624
Conversation
Accepted limitationsThree review rounds:
Valgrind is clean with both client libraries.
Generated by Claude Code |
|
Does this need #611, especially given that it's revisited? Unstack and implement against main. |
|
No, it doesn't: the diff against #611 mentions the busy guard only in context lines. I'm rebuilding this PR as a single commit on Generated by Claude Code |
Closes #615, closes #622. `dbDisconnect()` closes the connection first and frees its result afterward, so that closing the statement no longer reads the remaining rows of an unbuffered result. The methods of a result check that its connection is still open and fail with a clear error otherwise. `dbBind()` on an inactive result, such as one cancelled by a newer query, errors like `dbFetch()` does. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
504b037 to
5d4a99b
Compare
|
Done: this PR is now a single commit on Generated by Claude Code |
|
Resolve conflicts for the stack. |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
|
Done. The latest Generated by Claude Code |
Keep the deferred warning from this branch with the new text from #624. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
Resolve the conflict in src/DbResult.cpp by keeping both sides: fetch() and get_column_info() take layer 2's `bigint` argument and start with the check_connection() call from #624, as on main. cpp11 registrations are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7atAZVq1J42WzXJpS
Closes #615, closes #622. Based on
main; it doesn't depend on #611. #629 is stacked on it.Before this change,
dbDisconnect()with a live result only warned and closed the connection. A laterdbFetch()on that result crashed R with MariaDB Connector/C (#615). Likewise,dbBind()on a result that a newer query had cancelled crashed R with both client libraries (#622), althoughdbIsValid()already returnedFALSE.Change
DbConnection::disconnect()warns that a result was still in use and has been closed with the connection. It closes the connection withmysql_close()first, which detaches the result's statement, and only then frees the statement. Closing the statement first would make the client library read every remaining row.dbIsValid(rs)isFALSEafterwards.DbResult::check_connection()stops with "The connection of this result has been closed." at the start of fetch, bind, column info, both row counts anddbHasCompleted().bind()also stops with "Inactive result set" when the result is no longer the connection's current one. This fixesdbBind()on a result cancelled by a newer query crashes R #622.dbClearResult()after a disconnect keeps the existing "Expired, result set already closed" warning and returnsTRUE. Garbage collection of such a result is safe.dbDisconnect()from R code running duringdbFetch()frees the result being fetched #621 (a query ordbDisconnect()from R code running during a fetch) is fixed in fix: A fetch stops cleanly when R code it calls closes its result or connection #629, stacked on this PR.Tests
tests/testthat/test-dbDisconnect.R(new) covers queries, statements,immediate = TRUE, a parameterized query, garbage collection, and #622. On MariaDB servers, it also checks that disconnecting after fetching one row of a 20-million-row result takes less than 0.5 s. That took about 1 s before the close order was fixed, and takes 0.001 s now. Under valgrind, these tests andtest-dbClearResult.Rshow 0 errors with MariaDB Connector/C 3.3.17. With libmysqlclient 8.0.46, valgrind shows only 248 bytes "possibly lost" inside the library's own startup. Local runs against MariaDB 10.11 withNOT_CRAN=true, with both client libraries, after rebuilding this PR as a single commit onmain: the whole suite had 0 failures and the onetest-timezone.Rerror ("US/Alaska" unknown to CCTZ in this container), which also happens onmain. 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
Generated by Claude Code