Skip to content

R crashes if calling duck-ui with an overwritten connection object #1147

Closed

Description

@mns-nordicals

First create a duckdb connection and open the duck-ui

con <- DBI::dbConnect(duckdb::duckdb())
DBI::dbExecute(con, "CALL start_ui()")

close the browser and overwrite / create a new connection to duckdb

con <- DBI::dbConnect(duckdb::duckdb())

Now call the duckui again

DBI::dbExecute(con, "CALL start_ui()")

In positron I can get this error message / log

2025-05-06 23:37:53.749 [info] ** Begin kernel log for session R 4.5.0 (r-efa4682b) at 5/6/2025, 11:37:53 PM **
Streaming kernel log file: C:\Users\XXX\AppData\Local\Temp\kernel-G7luwG\kernel.log
terminate called after throwing an instance of 'duckdb::Exception'

what(): {"exception_type":"Settings","exception_message":"Setting "ui_polling_interval" not found"}

terminate called after throwing an instance of 'duckdb::Exception'

This will also crash in Rstudio.

I don't know if this is a duckdb-r issue, a duckdb issue or simply a user issue 😅

Activity

  1. krlmlr commented on Sep 7, 2025

    @krlmlr
    Collaborator

    Thanks. Can't reproduce with duckdb 1.3.2, R 4.4.3, latest RStudio on macOS. Is this still a problem?

  2. krlmlr commented on Aug 9, 2026

    @krlmlr
    Collaborator

    A gc() was needed to reproduce. This seems to be a duckdb-ui problem, please open an issue at https://github.com/duckdb/duckdb-ui. Workarounds:

    • Explicitly shut down the UI
    • Wait for a period larger than the ui_polling_interval setting (0.284 seconds)
    ## duckdb-r#1147 -- R crashes calling start_ui() with an overwritten
    ## connection object. The failure is an abort, not an R error, so each
    ## variant runs in its own process and we look at the exit status.
    library(duckdb)
    #> Loading required package: DBI
    packageVersion("duckdb")
    #> [1] '1.5.5.9012'
    
    variant <- function(...) {
      script <- tempfile(fileext = ".R")
      writeLines(c("library(duckdb)", ...), script)
      out <- processx::run(
        file.path(R.home("bin"), "Rscript"),
        script,
        error_on_status = FALSE,
        stderr_to_stdout = TRUE
      )
      cat(out$stdout)
      cat("exit status:", out$status, "\n")
    }
    
    # 1. The reporter's sequence: the second connection lands on the same name,
    #    so the first database is finalised while its UI server is still up
    variant(
      'con <- DBI::dbConnect(duckdb::duckdb(shared_home = TRUE))',
      'DBI::dbExecute(con, "INSTALL ui")',
      'DBI::dbExecute(con, "CALL start_ui_server()")',
      'con <- DBI::dbConnect(duckdb::duckdb(shared_home = TRUE))',
      'gc()',
      'DBI::dbExecute(con, "CALL start_ui_server()")',
      'cat("survived\\n")'
    )
    #> Loading required package: DBI
    #> [1] 0
    #> [1] 0
    #>           used (Mb) gc trigger (Mb) limit (Mb) max used (Mb)
    #> Ncells  658502 35.2    1465102 78.3         NA  1465102 78.3
    #> Vcells 1235585  9.5    8388608 64.0      32768  2077775 15.9
    #> libc++abi: terminating due to uncaught exception of type duckdb::Exception: {"exception_type":"Settings","exception_message":"Setting \"ui_polling_interval\" not found"}
    #> exit status: -6
    
    # 1a. Same shape, but the connection is disconnected before its database goes away.
    #     Still crashes.
    variant(
      'con <- DBI::dbConnect(duckdb::duckdb(shared_home = TRUE))',
      'DBI::dbExecute(con, "INSTALL ui")',
      'DBI::dbExecute(con, "CALL start_ui_server()")',
      'DBI::dbDisconnect(con)',
      'con <- DBI::dbConnect(duckdb::duckdb(shared_home = TRUE))',
      'gc()',
      'DBI::dbExecute(con, "CALL start_ui_server()")',
      'cat("survived\\n")'
    )
    #> Loading required package: DBI
    #> [1] 0
    #> [1] 0
    #>           used (Mb) gc trigger (Mb) limit (Mb) max used (Mb)
    #> Ncells  658764 35.2    1465102 78.3         NA  1465102 78.3
    #> Vcells 1235768  9.5    8388608 64.0      32768  2077775 15.9
    #> libc++abi: terminating due to uncaught exception of type duckdb::Exception: {"exception_type":"Settings","exception_message":"Setting \"ui_polling_interval\" not found"}
    #> exit status: -6
    
    # 1b. Same shape, but the driver is shut down before its database goes away.
    #     Still crashes.
    variant(
      'drv <- duckdb::duckdb(shared_home = TRUE)',
      'con <- DBI::dbConnect(drv)',
      'DBI::dbExecute(con, "INSTALL ui")',
      'DBI::dbExecute(con, "CALL start_ui_server()")',
      'DBI::dbDisconnect(con)',
      'duckdb::duckdb_shutdown(drv)',
      'con <- DBI::dbConnect(duckdb::duckdb(shared_home = TRUE))',
      'gc()',
      'DBI::dbExecute(con, "CALL start_ui_server()")',
      'cat("survived\\n")'
    )
    #> Loading required package: DBI
    #> [1] 0
    #> [1] 0
    #>           used (Mb) gc trigger (Mb) limit (Mb) max used (Mb)
    #> Ncells  659283 35.3    1465102 78.3         NA  1465102 78.3
    #> Vcells 1236276  9.5    8388608 64.0      32768  2077775 15.9
    #> libc++abi: terminating due to uncaught exception of type duckdb::Exception: {"exception_type":"Settings","exception_message":"Setting \"ui_polling_interval\" not found"}
    #> exit status: -6
    
    # 2. Same shape, but the first database stays alive: no crash
    variant(
      'con <- DBI::dbConnect(duckdb::duckdb(shared_home = TRUE))',
      'DBI::dbExecute(con, "INSTALL ui")',
      'DBI::dbExecute(con, "CALL start_ui_server()")',
      'con2 <- DBI::dbConnect(duckdb::duckdb(shared_home = TRUE))',
      'DBI::dbExecute(con2, "CALL start_ui_server()")',
      'cat("survived\\n")'
    )
    #> Loading required package: DBI
    #> [1] 0
    #> [1] 0
    #> [1] 0
    #> survived
    #> exit status: 0
    
    # 3. Same shape, but the server is stopped before its database goes away
    variant(
      'con <- DBI::dbConnect(duckdb::duckdb(shared_home = TRUE))',
      'DBI::dbExecute(con, "INSTALL ui")',
      'DBI::dbExecute(con, "CALL start_ui_server()")',
      'DBI::dbExecute(con, "CALL stop_ui_server()")',
      'con <- DBI::dbConnect(duckdb::duckdb(shared_home = TRUE))',
      'gc()',
      'DBI::dbExecute(con, "CALL start_ui_server()")',
      'cat("survived\\n")'
    )
    #> Loading required package: DBI
    #> [1] 0
    #> [1] 0
    #> [1] 0
    #>           used (Mb) gc trigger (Mb) limit (Mb) max used (Mb)
    #> Ncells  658502 35.2    1465102 78.3         NA  1465102 78.3
    #> Vcells 1235585  9.5    8388608 64.0      32768  2077775 15.9
    #> [1] 0
    #> survived
    #> exit status: 0
    
    # 4. Timing: give the finalised database a moment before the new
    #    server starts, and the same sequence survives.
    #    Should be larger than ui_polling_interval (0.284 seconds)
    variant(
      'con <- DBI::dbConnect(duckdb::duckdb(shared_home = TRUE))',
      'DBI::dbExecute(con, "INSTALL ui")',
      'DBI::dbExecute(con, "CALL start_ui_server()")',
      'con <- DBI::dbConnect(duckdb::duckdb(shared_home = TRUE))',
      'gc()',
      'Sys.sleep(0.3)',
      'DBI::dbExecute(con, "CALL start_ui_server()")',
      'cat("survived\\n")'
    )
    #> Loading required package: DBI
    #> [1] 0
    #> [1] 0
    #>           used (Mb) gc trigger (Mb) limit (Mb) max used (Mb)
    #> Ncells  658502 35.2    1465068 78.3         NA  1465068 78.3
    #> Vcells 1235585  9.5    8388608 64.0      32768  2077775 15.9
    #> [1] 0
    #> survived
    #> exit status: 0
    
    # which extension build this was
    con <- dbConnect(duckdb(shared_home = TRUE))
    dbExecute(con, "LOAD ui")
    #> [1] 0
    dbGetQuery(
      con,
      "SELECT extension_name, extension_version, install_mode
       FROM duckdb_extensions() WHERE extension_name = 'ui'"
    )
    #>   extension_name extension_version install_mode
    #> 1             ui           26084e6   REPOSITORY
    dbDisconnect(con, shutdown = TRUE)

    Created on 2026-08-09 with reprex v2.1.1

  3. added a commit that references this issue on Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions