Repository navigation
Conversation
The internal `read_arrow_stream()` returns a `nanoarrow_array_stream` whose `get_next()` fetches the next chunk of at most `n` rows of the result, built as `result_fetch_arrow_chunk()` builds it: the same column types, coercion warnings and byte limits. `get_schema()` reads the first chunk, which decides the types, and keeps it for the first `get_next()`, so that no row is handed out before the schema. The stream shares the result with its R object, so the result outlives a callback even if R frees the object meanwhile. Once `dbClearResult()` clears the result, which now frees its statement also while a stream holds a share, once the connection is closed, or once the result is bound to new parameters, the next `get_schema()` or `get_next()` fails with an error that says so. Errors of SQLite reach the consumer through `get_last_error()`, with the semantics of the fetch loop; an interrupt or a warning made an error continues its jump once the callback's C++ objects are destroyed. A result is fetched either as data frames or as an Arrow stream, whichever comes first: `claim_fetch_kind()` holds this rule in one place, so that it is easy to relax. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
|
Review of this pull request at 89e2751, by a Claude Code reviewer with clean context that read the description, the diff against the merged base head 975e379 (#863), the surrounding What was run
What holds
HighNone. Medium
Low
Generated by Claude Code |
…r, and make its failures final A `release()` called from a handler of a warning that the stream's own `get_schema()` or `get_next()` raises freed the state, and possibly the result, while the callback still used them. The state now counts its running callbacks: `release()` during one only marks the state released, and the callback deletes it once its body returns, before it continues an R jump. After a failed `get_next()`, by an error of SQLite, an interrupt or another error, later calls fail again with its message instead of ending the stream as if the rows were complete. A chunk kept when its warning exited still comes with the next call. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
CI: the full matrix is blocked by #836, not by this pull requestThe full matrix dispatched by hand for 89e2751 (run 43310606297) stopped after the smoke test, whose step "Write diff and fail for workflow_dispatch" found three files to regenerate: Any branch whose change regenerates Generated by Claude Code |
|
Second review round of this pull request, of a0f7fee, which addresses the two findings of the first round (the use-after-free on a What was run
What holds
HighNone. Medium
Low
Generated by Claude Code |
…ilures final A consumer that doesn't check `release` between chunks, such as nanoarrow's `convert_array_stream()`, calls `get_next()` again on a stream released from a handler; the callbacks now return `EINVAL` for a released stream without touching it, and `get_last_error()` returns a fixed message. A failure is never cleared once recorded, and `get_schema()` raises it as well until a schema is cached, so that a retry can't report an empty, complete stream. The count of running callbacks is kept by `R_ExecWithCleanup()`, also when an R error leaves a callback by a jump that bypasses cpp11. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
|
Third review round of this pull request, of db5b47a, which addresses the findings of the second round (a crash when a handler releases the stream during What was run
What holds
HighNone. MediumNone. Low
Generated by Claude Code |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
Superseded: Accepted limitationsSuperseded by the new copy. Three clean review rounds: the first of the whole pull request at 89e2751, the second of a0f7fee and the third of db5b47a. The first two found a crash when a handler releases the stream during its own callback (fixed by deferring the release and by failing every callback of a released stream with
Generated by Claude Code |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
Question: should the stream fail once R frees its result object without
|
Question: should the stream be safe to read on a thread other than R's main thread in this pull request?The stream's callbacks call R, through the fetch and the coercion warning, so they must run on R's main thread, and a
Kirill decides. If nobody decides, worker threads come with pull request 15. Generated by Claude Code |
Question: should the stream's callbacks also destroy their C++ objects when an R error leaves them by a jump that bypasses cpp11?Each callback body runs under
Kirill decides. If nobody decides, it stays as it is, recorded in the comment above Generated by Claude Code |
Superseded: Accepted limitationsSuperseded by the copy of 2026-11-29. Three clean review rounds: the first of the whole pull request at 89e2751, the second of a0f7fee and the third of db5b47a. The first two found a crash when a handler releases the stream during its own callback (fixed by deferring the release and by failing every callback of a released stream with
Found here, but on
Generated by Claude Code |
A stream raises a parameter that its read-ahead could not bind with its next chunk, and completes the result. A row held back for the byte limit of a chunk starts the next chunk. Running out of memory while reading a value fails the stream with an error of the stream, completes the result, and stays final. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd8MVXyvU7qoMeruD1R
Question: refuse a second Arrow stream on a result that already has one?The clean review of 2026-11-29 rated this Low. Refusing a second stream while one is open, with an error like "This result is already read by an Arrow stream.", costs a flag or a count on the result next to
The fix was not written in this session, whose harness refused to start an agent for fixes. Kirill decides. If nobody decides, it is accepted as a limitation. Generated by Claude Code |
Accepted limitationsThree clean review rounds: the first of the whole pull request at 89e2751, the second of a0f7fee and the third of db5b47a. The first two found a crash when a handler releases the stream during its own callback (fixed by deferring the release and by failing every callback of a released stream with The clean review of 2026-11-29, after
Generated by Claude Code |
Finding: A stream created before the first
|
The claim of a result for one kind of fetch now lives in `DbResult::claim_fetch_kind()` below. The stream claims the result for Arrow arrays when it is created, as the Arrow chunks do, and the R function `claim_fetch_kind()` with `result_claim_fetch_kind()` is gone. The errors read "Can't fetch a result as a data frame after fetching it as Arrow arrays." and the converse. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Pull request 9 of the Arrow rework plan. It stacks on #863 (Arrow chunks end before string and binary offsets overflow), which stacks on #862, #861, #860, #859, #857, #856, #855, #830 and #850.
What changes
A new internal entry point,
read_arrow_stream(res, n = 65536L), returns ananoarrow_array_streamover an open result. Eachget_next()fetches the next chunk of at mostnrows (all of them for-1) with the chunk machinery of #859 to #863: the same column types, the coercion warning once per chunk, and the byte limit that ends a chunk before its string or binary offsets overflow. Nothing is fetched when the stream is created.get_schema()reads the first chunk, which decides the column types as forresult_fetch_arrow_chunk(), and keeps it for the firstget_next(), so no row is handed out before the schema and the schema always matches the chunks. The schema is cached in the stream once read. A result without rows ends the stream without a chunk, with the types of the declared columns. No DBI method calls the stream yet, and the defaultdbFetch()path is unchanged except for the check below.Lifetime. The stream holds a share of the result (the
DbResultPtrfrom #856), so the result lives through every callback, also if R's garbage collector frees the R result object meanwhile.dbClearResult()now callsDbResult::clear(), which frees the statement and drops the connection even while a stream holds a share. The nextget_schema()orget_next()then fails with "Can't read an Arrow stream after its result has been cleared." It likewise fails afterdbDisconnect()("…after its connection has been closed.") and afterdbBind()starts a new execution, whose types may differ from the stream's schema ("…after its result has been bound to new parameters."). The stream never touches the freed statement: it checks these conditions before each fetch, and itsrelease()only drops its share. A stream that reaches its end drops its share at once.Errors. C++ errors, among them SQLite's, become the stream's
EIOwith the message inget_last_error(). The fetch loop is the same as forresult_fetch_arrow_chunk(), so #830's semantics hold: an error at the step that reads ahead after a full chunk is kept for the nextget_next(), any error completes the result, and the busy guard stops a warning handler from clearing the result during a fetch. An interrupt, or a coercion warning made an error byoptions(warn = 2), arrives as acpp11::unwind_exception. Its jump continues once the callback's C++ objects are destroyed, as at cpp11's entry points, and the chunk kept by #862 comes with the nextget_next(). Any other failure of a callback is final: laterget_next()calls, andget_schema()calls until a schema is cached, fail again with its message, rather than end the stream as if its rows were complete, so a consumer that goes on after an error or an interrupt can't take a truncated result for a complete one. The flag is never cleared once set.Release during a callback. A handler of a warning raised inside the stream's own
get_schema()orget_next()may call the stream'srelease(). The stream counts its running callbacks: such a release only marks the state released and detaches it from the C struct, and the callback deletes the state, with its share of the result, once its body returns and before it continues an R jump. Without this, the callback would write into the freed state, or into a freed result when R had dropped its object. A consumer that doesn't checkreleasebetween chunks, such as nanoarrow'sconvert_array_stream(), may call the released stream again: itsget_schema()andget_next()then returnEINVALwithout touching any state, andget_last_error()returns "The Arrow stream has been released." Each callback body runs underR_ExecWithCleanup(), so the count of running callbacks stays right even if an R error leaves the body by a jump that bypasses cpp11.Mixed fetches. This applies the recommended answer of the mixed-fetch question, which nobody has decided yet. Once a stream has been created for a result,
dbFetch()on it fails with an error of classRSQLite_error_fetch_kind. OncedbFetch()has been called on a result, with anyn, creating a stream fails likewise. The claim holds for the result's lifetime, also acrossdbBind(). The rule lives in one place,claim_fetch_kind()inR/arrow-stream.R: dropping its error allows mixing, which the internal fetches already support.result_fetch_arrow_chunk()is not part of the rule, so the tests of #859 that alternate the two kinds of fetch keep working.Deliberately left out
dbClearResult()ordbDisconnect(): pull request 10.release()that drops the last share destroys the result where it runs.dbSendQueryArrow(),dbFetchArrow()anddbFetchArrowChunk()through the stream: pull request 16.Error message
The error uses
rlang::abort()rather thancli::cli_abort(). cli is only in Suggests, anddbFetch()can raise this error.Tests
tests/testthat/test-arrow-stream.R, run through nanoarrow ($get_schema(),$get_next(),convert_array_stream()):dbGetRowCount()as the stream advances, and agreement withdbGetQuery()options(warn = 2), after which the stream goes on with the kept chunkdbClearResult(),dbDisconnect()anddbBind()get_next()keeps failing, and an SQLite error while the schema is read, after which threeconvert_array_stream()calls all failrelease()from a handler of the stream's own warning, with the R result object kept and with it freed, and from a handler duringconvert_array_stream()(also run under valgrind, with the reviews' reproducers)nEvery
test_that()block runs on its own afterload_all().devtools::test()withNOT_CRAN=truepasses except the three known errors intest-httpvfs.R(#832, #837), andR CMD check --no-manualpasses.https://claude.ai/code/session_01Hr1rd432Aef98ibnZSSsYn
Generated by Claude Code