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

Error in saveRDS in save_function_to_temp #292

Open
trafficonese opened this issue Nov 8, 2024 · 5 comments
Open

Error in saveRDS in save_function_to_temp #292

trafficonese opened this issue Nov 8, 2024 · 5 comments

Comments

@trafficonese
Copy link

In an R Shiny App I got a bug like this, which points to this function

save_function_to_temp <- function(options) {

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?

@gaborcsardi
Copy link
Member

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.

@trafficonese
Copy link
Author

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
Copy link
Author

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

@gaborcsardi
Copy link
Member

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.

@trafficonese
Copy link
Author

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

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