Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to silence warning "Database is garbage-collected ..." #34

Open
DavZim opened this issue Oct 17, 2023 · 4 comments
Open

Option to silence warning "Database is garbage-collected ..." #34

DavZim opened this issue Oct 17, 2023 · 4 comments
Milestone

Comments

@DavZim
Copy link

DavZim commented Oct 17, 2023

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.

con <- DBI::dbConnect(duckdb::duckdb(), "my-db.db")
on.exit(DBI::dbDisconnect(con, shutdown = TRUE), add = TRUE)

# do something with the database
# eventually I get
#> Warning: Database is garbage-collected, use dbDisconnect(con, shutdown=TRUE) or duckdb::duckdb_shutdown(drv) to avoid this.

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)?

@krlmlr
Copy link
Collaborator

krlmlr commented Dec 2, 2023

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?

@DavZim
Copy link
Author

DavZim commented Dec 2, 2023

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.

@krlmlr
Copy link
Collaborator

krlmlr commented Mar 24, 2024

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

@krlmlr
Copy link
Collaborator

krlmlr commented Apr 24, 2024

Is this still an issue with v0.10.1, on CRAN now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants