Repository navigation
fix: A query on a disconnected connection fails with a clear error - #640
Conversation
) dbSendQuery(), dbExecute(), dbBegin(), dbCommit() and dbRollback() failed with "bad_weak_ptr" after dbDisconnect(), and dbQuoteString() and dbGetInfo() with "Invalid connection". All now fail with "Invalid or closed connection". Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
…637) 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. It confirmed that a cleared pointer can't be freed twice, that valid connections pay only one null check outside the fetch path, and that every R caller of
Generated by Claude Code |
|
The red "MySQL server" job (job 141391540221) is not this PR's. Its 23 failures are exactly those of #638, which Generated by Claude Code |
result_create() keeps the deferred warnings and the re-check after the cancel warning from #632, and reads the connection through connection_ptr(), so that a connection closed by a handler fails with "Invalid or closed connection". Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ
Fixes #637.
After
dbDisconnect(), the connection's external pointer is cleared.result_create(),connection_begin_transaction(),connection_commit()andconnection_rollback()dereferenced it with cpp11'soperator*, which throwsstd::bad_weak_ptr. SodbSendQuery(),dbSendStatement(),dbGetQuery(),dbExecute(),dbBegin(),dbCommit()anddbRollback()failed with "bad_weak_ptr". The functions that take aDbConnection*(dbGetInfo(),dbQuoteString(),dbWriteTable()) already failed with "Invalid connection" throughas_cpp(). Nothing crashed.connection_ptr()insrc/RMariaDB_types.h, stops with "Invalid or closed connection", the wordingDbConnection::check_connection()already uses.as_cpp()and the four external-pointer entry points use it.dbExistsTable(), which checks validity in R, uses the same message.dbIsValid()and the "Already disconnected" warning are unchanged.tests/testthat/test-dbDisconnect.Rgets one self-contained test that calls eleven methods on a disconnected connection, plus a seconddbDisconnect().Tests: built locally, and each entry point was checked against a connection with a cleared pointer. The local database server is down, so the test suite runs in CI only: a dispatched R-CMD-check smoke test against a live server passed on the first commit (FAIL 0, PASS 9092) in run 46275762621. The full matrix did not run.
Accepted limitations
🤖 Generated with Claude Code
https://claude.ai/code/session_01Hr1rd5PUWgaCJzotWt9NhJ