callr icon indicating copy to clipboard operation
callr copied to clipboard

Error in saveRDS in save_function_to_temp

Open trafficonese opened this issue 1 year ago • 5 comments

In an R Shiny App I got a bug like this, which points to this function https://github.com/r-lib/callr/blob/2dbb6e03713bc8a6025687c13c39bb40836dc1ec/R/setup.R#L13

Warnung: Error in saveRDS: Schreibfehler in Verbindung
  95: h
  94: .handleSimpleError
  93: saveRDS
  92: withCallingHandlers
  91: suppressWarnings
  90: save_function_to_temp
  89: eval
  88: eval
  87: within.list
  86: within
  85: setup_script_files
  84: rp_init
  83: initialize
  82: r_process$new
  81: r_bg
  80: eval
  79: eval
  78: with_stealth_rng
  77: run.CallrFuture
  76: run
  75: run.Future
  74: run
  73: future
  72: observe [/root/server.R#4833]

and the relevant part in server.R looks like this:

observeEvent(input$saveDB, ignoreNULL = TRUE, ignoreInit = TRUE,  {
  progress = AsyncProgress$new(message="Save Changes")
  
  myFuture <- future(seed = NULL, label = "SaveToDatabase", {
    progress$inc(0.1, message = "Connect to DB")
    con_fut <- dbConnect(drv = RPostgres::Postgres(),
                         dbname   = GLOBALS[["db"]][["dbname"]],
                         host     = GLOBALS[["db"]][["dbhost"]],
                         port     = GLOBALS[["db"]][["dbport"]],
                         user     = GLOBALS[["db"]][["dbuser"]],
                         password = GLOBALS[["db"]][["dbpwd"]],
                         bigint  = "integer",
                         timezone = "CET",
                         timezone_out = "CET")
    on.exit(dbDisconnect(con_fut), add = TRUE)
    progress$inc(0.1, message = "DB connected. Save changes.")
    handle_changes(con_fut, current_changes, tablename, progress)  ## separate function to create SQL UPDATEs and execute them
  })
  then(
    myFuture,
    onFulfilled = function(value) {
      if (!is.null(value$errors)) {
        showNotification(unique(value$errors)[[1]], session = session, type = "error")
      }
      progress$close()
    },
    onRejected = function(reason) {
      showNotification("Could not save changes", session = session, type = "error")
      progress$close()
      write("Changes saved successfully", file = logfile, append = TRUE)
    }
  )
  return(NULL)
})

Unfortunately I dont have a reproducible example, but its a bit tricky with the DB and the SQL-creation function, but I thought maybe you have an idea why that error happens?

trafficonese avatar Nov 08 '24 09:11 trafficonese

Unfortunately this is not enough information. Maybe your disk is full? Or you are not allowed to write to that directory for some reason. It is really impossible to tell what the problem could be.

gaborcsardi avatar Nov 08 '24 10:11 gaborcsardi

Hm yeah I thought so. I doubt that those would be the problems, as most of the times this process works fine, so I have writing permissions and the disk has plenty of available space. I will add some more logging to the app, maybe that will help in resolving this. Thanks for your quick reply though!

trafficonese avatar Nov 08 '24 10:11 trafficonese

But maybe you could give me a quick explanation.. The function rs_call is called for every process method call (inc, close, etc)?

trafficonese avatar Nov 08 '24 10:11 trafficonese

rs_call() is for r_session objects and based on the stack you are not using r_session objects. I have no idea what inc is, that's not from callr for sure.

gaborcsardi avatar Nov 08 '24 10:11 gaborcsardi

yes, you're right, it's from the ipc package and the AsyncProgress https://github.com/fellstat/ipc/blob/master/R/async-progress.R

trafficonese avatar Nov 08 '24 11:11 trafficonese