Repository navigation
Conversation
A stream of `read_arrow_stream()` now reads on, lazily and chunk by chunk, after its result is cleared or its connection is closed, as `dbGetQueryArrow()` needs, since it clears the result before the stream is consumed. `dbClearResult()` drops only R's share of the result: the statement lives as long as a stream shares it, and is finalized when the last stream ends or is released. `dbDisconnect()` defers closing the connection while a stream reads from it, so the stream keeps a fully open handle with its busy handler, and the connection is closed once the last stream has ended or is released. A result whose connection is already closed can't start a stream. `dbIsValid()`, the errors and warnings of `dbClearResult()`, and the busy guard are unchanged. The warning of `dbDisconnect()` about results in use counts them as before: a cleared result that a stream still reads doesn't count. A stream still fails after `dbBind()`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
The CI's auto-update regenerated `src/cpp11.dd` and `src/result.dd` with GCC, whose dependency output indents continuation lines by one space, which the filter in `src/Makevars.deps` does not drop, so the files gained hundreds of absolute and vendored paths (#836). This restores them as they were at 79efd5d and keeps the auto-update's formatting of `src/result.cpp`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
|
Review of this pull request at 79efd5d, by a Claude Code reviewer with clean context that read the descriptions of #865 and #864, the diff against 075d214 with the code around it ( What was run
What holds
HighNone. Medium
Low
Generated by Claude Code |
…im no stream on a closed one A connection closed by `dbDisconnect()`, or by the last Arrow stream that reads it, can stay a zombie while an open result holds a statement. SQLite could then call the R busy handler after it had been released, as when `dbBind()` on such a result met a lock: the handler is now unregistered from SQLite before the handle is closed, and the result fails at once instead. This also holds without streams. `read_arrow_stream()` checks the connection before it claims the result, so that a failed call leaves `dbFetch()` usable. A result that R's garbage collector frees while a stream reads it no longer counts as in use for `dbDisconnect()`, as a cleared one: its finalizer now marks it as `dbClearResult()` does. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
|
Second review round of this pull request, of e8d0917, by a Claude Code reviewer with clean context that read the description, the diff against bb119a5 with the code around it ( What was run
What holds
HighNone. MediumNone. Low
Generated by Claude Code |
…ult code of its errors Closing a connection unregisters the busy handler only when it is an R function, so a busy timeout set by `sqliteSetBusyHandler()` with an integer or by `PRAGMA busy_timeout` keeps working for the statements of open results, as before. An error of such a statement, whose handle has been closed, reports SQLite's message for its result code, such as "database is locked", since `sqlite3_errmsg()` of a closed handle only reports API misuse. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
Superseded: Accepted limitationsSuperseded by this newer copy. Two clean review rounds: the first of the whole pull request at 79efd5d, the second of e8d0917. The first found that the R busy handler could be released while SQLite could still call it (also on
Generated by Claude Code |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
Question: buffer the rest of a result when its Arrow stream outlives
|
Question: make the final close of a statement and a connection safe off R's main thread now, rather than in pull request 15?With this pull request, the last
If nobody decides, the final close runs where Generated by Claude Code |
Superseded: Accepted limitationsSuperseded by the copy of 2026-11-29. Two clean review rounds: the first of the whole pull request at 79efd5d, the second of e8d0917. The first found that the R busy handler could be released while SQLite could still call it (also on
Generated by Claude Code |
…time Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
…time Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
…time Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd8MVXyvU7qoMeruD1R
Question: keep a
|
Accepted limitationsTwo clean review rounds: the first of the whole pull request at 79efd5d, the second of e8d0917. The first found that the R busy handler could be released while SQLite could still call it (also on The clean review of 2026-11-29, after
Generated by Claude Code |
…time The stream claims its result in C++ after the check of the connection, so a call refused for a closed connection claims nothing without a check in R. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Pull request 10 of the Arrow rework plan. It stacks on #864 (a result read as a lazy Arrow array stream), which stacks on #863, #862, #861, #860, #859, #857, #856, #855, #830 and #850.
What changes
A stream of the internal
read_arrow_stream()now keeps working afterdbClearResult()anddbDisconnect(), where #864 failed its next callback. These are the semantics that DBI'sdbGetQueryArrow()needs, since it clears the result before the stream is consumed.After
dbClearResult(). The stream already holds a share of the result (#856, #864).dbClearResult()now only drops R's share, rather than freeing the statement under the stream: the statement lives as long as a stream shares the result, and is finalized when the last stream that reads it ends or is released, byrelease()or by R's garbage collector. A result without a stream is destroyed at once, as before. The stream keeps reading lazily, one chunk perget_next(), also while other statements run on the connection.After
dbDisconnect(). The connection counts the streams that read from it. While one does,dbDisconnect()marks the connection closed for R (dbIsValid()isFALSE, every later use fails as before) but leaves the SQLite handle open, with its busy handler; the last stream to end or be released then closes it withsqlite3_close_v2(), which completes once the statements are finalized. Without a stream,dbDisconnect()closes the handle at once, as before. Deferring the close, rather than reading through the zombie handle thatsqlite3_close_v2()leaves, keeps the connection fully usable for the stream: its errors keep SQLite's message (the old stack had to fall back tosqlite3_errstr()), its virtual tables stay connected, and its R busy handler stays registered and is called as before. A result whose connection is already closed can't start a stream ("Can't read a result as an Arrow stream after its connection has been closed."), so a stream never reads through a zombie handle.read_arrow_stream()checks this before it claims the result for Arrow, so a failed call leavesdbFetch()usable.The busy handler of a closed connection. Before every close, immediate or deferred, an R busy handler is now unregistered from SQLite (
sqlite3_busy_handler(conn, NULL, NULL)) and only then released. An uncleared result can still step its statement through the zombie handle, withdbFetch()ordbBind(); until now SQLite could then call the released R closure ("attempt to apply non-function", or a crash), on #864 and onmainafter a plaindbDisconnect()with an open result as well. Such a step now fails at once with "database is locked". A busy timeout, set bysqliteSetBusyHandler()with an integer or byPRAGMA busy_timeout, calls no R code and stays, so such a step still waits for it, as onmain.Errors through a closed handle.
sqlite3_errmsg()of a zombie handle only reports API misuse, so an error of a statement stepped after its connection was closed read "bad parameter or other API misuse" (also onmain). Once the handle is closed, the error now carries SQLite's message for the step's result code (sqlite3_errstr()), such as "database is locked". While a stream keeps the handle open afterdbDisconnect(), errors keep SQLite's full message.Unchanged.
dbIsValid()of the result and the connection, the warnings and errors ofdbClearResult(),dbFetch()anddbDisconnect()on the default path, and #830's busy guard, which still makesdbClearResult()refuse while a fetch runs, also from a handler of a stream's own warning. The warning ofdbDisconnect()about results in use counts them as before: a result cleared while a stream still reads it doesn't count (#864 got this by dropping the connection inclear(); now the connection counts such results). A result that R's garbage collector frees while a stream reads it doesn't count either, unlike on #864: the finalizer of the result's external pointer now marks it asdbClearResult()does. A stream still fails afterdbBind(), whose types may differ from its schema. The release during a callback, the final failures and the mixed-fetch claim of #864 are untouched.Lazy, not buffered. A stream reads its rows lazily after the clear, because buffering would hold the whole rest of the result in memory, which defeats a stream, and would have to read it eagerly inside
dbClearResult(), where errors and coercion warnings would surface at the wrong call. The price: until the stream has ended or is released, it keeps its statement open, and with it a read transaction and the database file, also afterdbDisconnect(). Meanwhile, on the same connection,DROP TABLEon a table it reads fails with "database table is locked", and on a file database another connection's writes fail with "database is locked"; a transaction left open atdbDisconnect()is rolled back only when the connection finally closes. This is what a pending statement means in SQLite, and the old stack documented the same.Deliberately left out
release()still destroys the result, and now possibly closes the connection, on the thread where it runs, which must be R's main thread.dbSendQueryArrow(),dbFetchArrow(),dbFetchArrowChunk()anddbGetQueryArrow()through the stream, and user documentation of the lifetime: pull request 16.Tests
tests/testthat/test-arrow-stream-lifetime.R, through nanoarrow:dbFetch()rm()andgc()of the result and the connection while a stream lives, also of a connection never disconnectedgc()while a stream reads it doesn't count as in usedbDisconnect()while a stream lives and called through the deferred handle, then not called once the stream's release closed it; and not called after a plaindbDisconnect()with an open result, where the result fails with "database is locked" (on feat: Let Arrow streams outlivedbClearResult()anddbDisconnect()#865's first commit this test aborts R)options(warn = 2)and a release from a handler of the stream's own warning, after clear and disconnectdbDisconnect(): three streams of one connection, one released before its end, one read to its end and then released, one freed bygc(); another connection stays locked out until the last of them, and then sees the transaction rolled back, so the connection was closed exactly thenThe two tests of
test-arrow-stream.Rthat expected the failures are gone. Every new block fails on #864 and passes on its own afterload_all().devtools::test()withNOT_CRAN=truepasses except the three known errors intest-httpvfs.R(#832, #837). A script of default-path behavior (fetch after disconnect, clearing twice, disconnecting twice, results freed) prints the same on #864 and here; the only intended changes on the default path are the busy handler and the error message through a closed handle above.valgrind (
--leak-check=full): no errors and nothing definitely lost fortest-arrow-stream-lifetime.R,test-arrow-stream.Randtest-dbClearResult.R, nor for the review's reproducers (busy handlers, lifetimes in every order ofrm()andgc(), the claim, the default path), nor for reproducers that release a stream of a cleared result of a disconnected connection, with a custom busy handler, from a handler of its own warning duringget_next()andconvert_array_stream(), that leave a stream byoptions(warn = 2)and free it bygc(), and that release ten streams of one connection in random order, before and after their end.https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
Generated by Claude Code