Skip to content

fix: sqliteSetBusyHandler(con, NULL) removes the busy handler instead of crashing R - #969

Draft
krlmlr wants to merge 2 commits into
mainfrom
claude/fix-busy-handler-null
Draft

krlmlr wants to merge 2 commits into
mainfrom
claude/fix-busy-handler-null

Conversation

@krlmlr

@krlmlr krlmlr commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Closes #968.

sqliteSetBusyHandler(con, NULL) now removes the busy handler and any timeout, so that a locked database fails immediately with "database is locked", as ?sqliteSetBusyHandler documents for NULL. Before, set_busy_handler() registered busy_callback_helper() with NULL data, and the next busy event aborted R, whether or not a handler or timeout had been set before. set_busy_handler() now always unregisters the previous handler first, and returns after releasing the R callback when given NULL. disconnect() also unregisters the busy handler before it releases the R callback, because sqlite3_close_v2() keeps the handle alive while statements remain. ?sqliteSetBusyHandler now says that NULL also removes a timeout or handler function set before, and that each call replaces what the previous one set.

The new test in test-dbConnect.R runs the busy events in a callr::r() subprocess, so that a regression fails the test instead of aborting the test run. Like the existing interrupt test, it uses the installed package. It checks NULL on a fresh connection, after a function handler and after a timeout, each failing with "database is locked" in under five seconds. Red on main (fb8effe): the subprocess crashes (callr subprocess failed: ... has crashed or was killed). Green with the fix. A sibling subprocess test checks that a replaced handler function is no longer called, that a function set after a timeout is called, and that a handler still set at dbDisconnect() while a result is open neither crashes R nor is called; it passes on main too and guards against regressions. Full suite with NOT_CRAN=true: FAIL 0, WARN 3, SKIP 63, PASS 10716.

This fix is not part of the rebuilt chain planned in #880.

Coordinating session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4



Generated by Claude Code

…ad of crashing R

`set_busy_handler()` registered `busy_callback_helper()` with `NULL` data when given `NULL`,
so the next busy event aborted R.
It now unregisters the busy handler, which also clears a timeout,
so that a locked database fails immediately as documented.
`disconnect()` unregisters the busy handler before it releases the R callback.

Closes #968.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
… or handler

`NULL` also removes a timeout or handler function set before,
and each call replaces what the previous one set.
A new subprocess test checks that a replaced handler is no longer called,
and that a handler still set at `dbDisconnect()` with an open result does not crash R.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqliteSetBusyHandler(con, NULL) crashes R on the next busy event

2 participants