nbenn commented on issue #323:
URL:
https://github.com/apache/arrow-nanoarrow/issues/323#issuecomment-1825912658
I've been playing around a bit more. Some observations:
- My own `as_data_frame()` was not cleaning up after itself properly. I was
missing something like
https://github.com/apache/arrow-nanoarrow/blob/97bb65edd2c45fc1ad80574d8ef6009466762428/r/R/array-stream.R#L167-L167
- Later then I go ahead and release the statement via
`adbcdrivermanager::adbc_statement_release()` with the array stream for this
statement still alive.
- The array stream has gone out of scope/is not bound anywhere anymore, so
at some point the `R_RegisterCFinalizer()`-registered
`finalize_array_stream_xptr()` is triggered.
https://github.com/apache/arrow-nanoarrow/blob/97bb65edd2c45fc1ad80574d8ef6009466762428/r/src/array_stream.h#L60
- Do you then maybe try to release the statement again when finalizing the
array stream because the lifetime of the two objects is somehow linked?
Otherwise I don't understand why this causes problems.
The following is an adbi-free reproducible example:
```r
library(adbcdrivermanager)
db <- adbc_database_init(adbcsqlite::adbcsqlite(), uri = ":memory:")
con <- adbc_connection_init(db)
i <- 0
while (i < 10) {
message(i <- i + 1)
stmt <- adbc_statement_init(con)
adbc_statement_set_sql_query(stmt, "SELECT $1 + 1.0 AS a")
adbc_statement_prepare(stmt)
params <- nanoarrow::nanoarrow_schema_parse(
adbc_statement_get_parameter_schema(stmt),
recursive = TRUE
)
adbc_statement_bind_stream(
stmt,
data.frame(c(0.5, 1.5, 2.5), fix.empty.names = FALSE)
)
res <- nanoarrow::nanoarrow_allocate_array_stream()
adbc_statement_execute_query(stmt, res)
ptype <- nanoarrow::nanoarrow_array_init(
nanoarrow::infer_nanoarrow_schema(res)
)
nanoarrow::convert_array_stream(res, function(schema, ptype) ptype)
adbc_statement_release(stmt)
}
```
Running this once or twice triggers the crash for me.
I guess in some sense it's a user error. At the same time such an unorderly
cleanup can easily happen and I guess it'd be nice to not crash the process.
Also this does not seem like a nanoarrow issue, so I probably did open up in
the wrong place.
Up to you how to go about this. Maybe error when trying to release a
statement with a not-yet released array stream associated? Also if my
assumption above is correct that you somehow try to re-release the statement,
that'd have to be conditional on the statement still being alive.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]