Open DavZim opened 11 months ago
Thanks. An option could be a stop gap while we're figuring out the correct solution.
Is this warning also shown when correctly pairing dbConnect()
and dbDisconnect()
calls?
What do you mean by stop gap exactly?
The message typically comes after some time using connection. So even if the disconnect is called later in a script, the warning is still shown.
This looks much better in #124, I'll merge it today, binaries will be available on https://duckdb.r-universe.dev/duckdb# soon. Can you confirm?
Likely a duplicate of #60.
fn <- function() {
con <- DBI::dbConnect(duckdb::duckdb(), "my-db.db")
on.exit(DBI::dbDisconnect(con), add = TRUE)
}
fn()
gc()
#> used (Mb) gc trigger (Mb) limit (Mb) max used (Mb)
#> Ncells 849819 45.4 1453881 77.7 NA 1453881 77.7
#> Vcells 1529519 11.7 8388608 64.0 24576 2696134 20.6
Created on 2024-03-24 with reprex v2.1.0
Is this still an issue with v0.10.1, on CRAN now?
@krlmlr I can confirm that this still happens in 1.0.0-2. But it doesn't happen all the time. Only after some repetition. I started using duckdb
in my package instead of arrow
due to less dependencies.
I use this to read multiple parquets at once with lapply
.
read_parquet <- function(x) {
mem_conn <- dbConnect(duckdb())
on.exit(dbDisconnect(mem_conn))
dbGetQuery(
conn = mem_conn,
statement = sprintf("SELECT * FROM '%s'", x)
)
}
read_parquet(
"~/testing.parquet"
)
I noticed warnings starts to occur after ~5th repetition. Warnings are repeated anywhere between 3 ~ 8 like so:
Warning: Connection is garbage-collected, use dbDisconnect() to avoid this.
Warning: Connection is garbage-collected, use dbDisconnect() to avoid this.
Warning: Connection is garbage-collected, use dbDisconnect() to avoid this.
Thanks. I can't replicate this. What OS are you on?
library(duckdb)
#> Loading required package: DBI
arrow::write_parquet(
x = data.frame(a = 1:10, b = letters[1:10]),
"testing.parquet"
)
read_parquet <- function(x) {
mem_conn <- dbConnect(duckdb())
on.exit(dbDisconnect(mem_conn))
dbGetQuery(
conn = mem_conn,
statement = sprintf("SELECT * FROM '%s'", x)
)
}
gctorture(10001)
for (i in 1:100) {
read_parquet(
"testing.parquet"
)
}
Created on 2024-08-16 with reprex v2.1.0
In my scripts where I connect to a duckdb, I oftentimes get the warning
Database is garbage-collected, use dbDisconnect(con, shutdown=TRUE) or duckdb::duckdb_shutdown(drv) to avoid this.
.When I use duckdb in combination with a shiny app or need to work with many different databases sequentially this clutters the console as the warning is repeated n-times.
The responsible line is
src/database.cpp#L12
.Is it possible to have an option to silence the warning? Maybe something like
option(duckdb.silence.disconnect_warning = TRUE)
?