Repository navigation
Conversation
…ailures final, and always return from its callbacks A `release()` from a handler of a warning that `get_next()` raises freed the state of the stream while the callback still used it. It now only marks the state released, and the callback deletes it once its body has returned. Later callbacks of the released stream fail with `EINVAL`. A failure is final: after an error of SQLite, later calls fail with the same code and message instead of ending the stream as if its rows were complete, and `get_schema()` fails too until a schema has been read. A cleared or rebound result fails with `EINVAL`, an error of SQLite with `EIO`. The callbacks no longer continue an R jump through the consumer's frames. An error or interrupt while the warnings are raised, as from a warning made an error with `options(warn = 2)`, is caught in R, and a jump by a handler further out that exits ends in the callback. The callback fails with `EAGAIN` and the message of the condition, and the result keeps the chunk for the next `get_next()`, so that such a failure is not final. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
…ude/rb-arrow-stream-robust
… only `condition_message()` converts the saved message with cpp11, so that an R error in the conversion ends in its catch, and the R helper is named `stream_condition_message()`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
…nds its result and exits A jump out of the warnings after a handler cleared the result or bound it to new parameters now fails the stream for good with `EINVAL` and the message for that case, rather than with `EIO` and the warning's message. An interrupt of the fetch fails it with `EINTR` and the message of an interrupt of the warnings; it stays final, since the interrupted fetch ends the result's execution. The internal `arrow_stream_error_codes()` gives the error codes, which differ between systems, to the tests. The comments say that a retry after `EAGAIN` goes on after the last chunk returned, and that a jump to the top level ends in the callback after R has reported it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
…as ended An interrupt ends the execution of the fetch it interrupts, and the rows that fetch read are lost. The result now records it for an execution claimed for Arrow fetches: every later Arrow fetch of the execution, through any stream or `fetch_arrow_chunk_warn()`, fails with an error that says so, until a bind starts a new execution, and `dbHasCompleted()` is `FALSE`, as its remaining rows can't be read. A stream reports it with `EINTR`. Tests simulate the interrupt with the internal `result_set_interrupt_after_rows()`. Another R condition that leaves the fetch or the stream's R code by a jump, such as an R error of a busy handler, fails with `EIO` and a message that doesn't claim an interrupt. The message of an interrupt of the warnings is written in C++ only. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
… into claude/rb-arrow-stream-lifetime Keeps the messages of #965's latest head over the CI's reformatting of the older ones. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
…s ended Any failure that ends an execution claimed for Arrow fetches, such as an error of SQLite, a value beyond the byte limit or an interrupt, loses the rows of its fetch. The result now records it, and every later Arrow fetch of the execution raises it again, through any stream or `fetch_arrow_chunk_warn()`, until a bind starts a new execution; `dbHasCompleted()` is `FALSE` for it. The chunk fetch tests expect this now. Data frame fetches are unchanged. An Arrow fetch checks for interrupts through `R_tryCatch()`, so that an R error that R raises while it processes events, such as the one of `setTimeLimit()`, fails with its message rather than as an interrupt. It checks every 16384 rows, since the check costs some microseconds. The tests' simulated interrupt applies to Arrow fetches only, raises a C++ error rather than jumping to the top level, and a bind disarms it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Question: how often should an Arrow fetch check for interrupts, now that the check tells an interrupt from an R error?An Arrow fetch checks for a user interrupt every so many rows. R's check also processes events, which can raise ordinary R errors, for example from
Kirill decides. Until then the first option stays as implemented. Generated by Claude Code |
No change of behavior for users: the Arrow stream of #964 is still internal. This makes it robust in three ways that #964 left open.
Release from a handler. A
release()called from a handler of a warning thatget_next()raises freed the stream's state while the callback still used it (a crash, or an invalid write under valgrind). Nowrelease()during a callback only marks the state released; the callback deletes it once its body has returned, and it holds the result until then, so R may free the result meanwhile. The call that was running finishes; a consumer that calls the released stream again without checking its release callback, as nanoarrow'sconvert_array_stream()does, getsEINVALand "Can't read an Arrow stream after it has been released." fromget_last_error().Final failures. After an error of SQLite, the next
get_next()returned the end of the stream, as if the rows were complete. Now a failure is final: every laterget_next()returns the same error code andget_last_error()keeps the message, also after the result is cleared.get_schema()still returns a schema read before, and fails the same way if the failure came before a schema was read (before, it then reported an empty schema and nanoarrow converted an empty, complete stream). The codes:EIOfor an error of SQLite or another failure of the fetch,EINTRfor an interrupt of the fetch,EINVALfor a result that is cleared or bound to new parameters and for a released stream,EBUSYfor the refused call from a handler (#964), andEAGAINbelow. An interrupt of the fetch is final rather than retryable because the interrupted fetch ends the result's execution and loses the rows it had read.Failed executions. Any failure that ends an execution claimed for Arrow fetches (an error of SQLite, a value beyond the byte limit, running out of memory, an interrupt, an R error) loses the rows of that fetch. The result now records it for the execution: every later Arrow read of it (this stream, another or a new stream on the result,
fetch_arrow_chunk_warn()) fails again with the same error, instead of ending as if the rows were complete, until a bind starts a new execution or the result is cleared. An error of SQLite comes back as anRSQLite_errorwith its code, an interrupt as "An interrupt has ended the Arrow fetches of this result." A chunk the result kept before is still handed out first.dbHasCompleted()isFALSEfor such an execution, because its remaining rows weren't read and can't be; so a loop ondbHasCompleted()fails rather than stopping early. This changes the expectations of the chunk fetch tests of #954–#963, which expectedTRUEand an empty chunk after a failure, and are updated here. Data frame fetches keep their behavior.To tell an interrupt from an R error that R raises while it processes events, such as the one of
setTimeLimit(), an Arrow fetch checks for interrupts throughR_tryCatch(): an interrupt givesEINTR, an R errorEIOwith the condition's message. Because that costs some microseconds, an Arrow fetch checks every 16384 rows (and every 16000 parameter sets without rows) instead of 1024 and 1000; data frame fetches still let the interrupt go on to R. An R error that leaves the fetch otherwise, such as from a busy handler, givesEIOwith "An R condition stopped reading an Arrow stream." The tests simulate an interrupt of an Arrow fetch with an internal hook,result_set_interrupt_after_rows(), which a bind disarms and a data frame fetch ignores.No R jump through the consumer. The callbacks no longer continue an R jump (
R_ContinueUnwind()) through the consumer's C or C++ frames, which the C stream interface forbids. The warnings about converted values are raised by a small R function that catches an error or interrupt among them, such as a warning made an error withoptions(warn = 2), and returns its message; a jump that still leaves it, as by a handler further out that exits, ends in the callback, which drops the continuation. Either way the callback returnsEAGAINwith the message of the condition, and the result keeps the chunk (#962), so the nextget_next()hands it out without warning again. An interrupt of the warnings gives "Raising the warnings of an Arrow chunk was interrupted." Such a failure is therefore not final, unless a handler has cleared the result or bound it to new parameters before the jump: then the call fails withEINVALand the message of #964 for that case, for good. A retry afterEAGAINgoes on after the last chunk that a call returned: a consumer that drops the chunks it got before the failure, asconvert_array_stream()does, doesn't get them again. Consequences worth knowing: handlers further out don't see an error from a warning made an error; they see the error that nanoarrow raises for the failed callback, with the same message. AtryCatch(warning = )around the stream no longer exits through its handler; the call fails with the warning's message instead. A condition raised by a handler further out (say,stop()in a calling handler of the warning) is reported with the message of the warning, since the stream can't see it. A jump to the top level, such as an unhandled error in such a handler,invokeRestart("abort")orQin the browser, also ends in the callback, after R has already reported the error; nanoarrow then reports a second error for the failed callback. The callback can't continue the jump, so this stays.Tested in
test-arrow-stream.R: release from a warning handler duringget_next()(also with the result dropped and garbage-collected in the handler) and duringconvert_array_stream(), calls after release, an SQLite error mid-stream followed by repeatedget_next()calls (same code[5]and message each time, also after clearing) and during the schema read (get_schema(),get_next()andconvert_array_stream()repeated),EINVALfor a cleared result,options(warn = 2)and an exiting handler both withget_next()and while nanoarrow converts, with the chunk recovered afterwards, a handler that clears or rebinds the result before it exits (EINVAL, final), a simulated interrupt of a fetch, both of the stream's own call and of another stream read from a warning handler, followed by reads through the same stream, another stream, a new stream andfetch_arrow_chunk_warn(), then a rebind, the same for an error of SQLite, and an R error fromsetTimeLimit()while the fetch checks for interrupts. The tests take the error codes from C rather than hard-coding them. Red on #964's head: 14 failures, then a segfault in the release test; green with the fix. The new test file is clean under valgrind (0 errors, no leaks); the full suite passes withNOT_CRAN=true(FAIL 0).Layer F6b of the rebuilt chain, planned in #880; based on #964. Ported from the old chain's commits a0f7fee and db5b47a (#864), adapted to #964's design: the state's
runningflag defers the release, a kept chunk decides whether a failure is final, and the result's clear semantics stay those of #964's weak reference (noclear()that frees the implementation). Keeping the result alive and package unload are left to F7. The third item comes from the review of #964.Coordinating session: https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
https://claude.ai/code/session_01Hr1rd7QnTD4acgzTUihnF4
Generated by Claude Code