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

Endpoint with octet serializer which receives a file in the request freezes whole Plumber.R execution #943

Open
1 task done
ihamod opened this issue Jan 19, 2024 · 0 comments

Comments

@ihamod
Copy link

ihamod commented Jan 19, 2024

System details

rstudio/docker v1.2.0 image
R version 4.3.2 (2023-10-31) -- "Eye Holes"
Platform: x86_64-pc-linux-gnu (64-bit)
Deployment: nginx / HAProxy 1.6.7

Problem description

In the specific application a zip file is uploaded to the server. The zip file is unzipped and then after some processing another zip file is produced and gets returned in the response. If the endpoint receives a request while it's working, the R application freezes and produces the following output, for any request to any other endpoint of plumber.R.

After some tests, we ascertained that this happens only when the Plumber application is deployed for load balancing through nginx and HAProxy 1.6.7 (according to https://www.rplumber.io/articles/hosting.html)

Error in file(open = "w+b", encoding = "UTF-8") :
cannot open the connection
Calls: -> file
In addition: Warning message:
In file(open = "w+b", encoding = "UTF-8") :
cannot open file '/tmp/Rtmpa4GHwN/Rf17deb5ac8': No such file or directory [the exact path changes with every request]

* @param f:file
#* @post /meditsrome2
function(f, res) {
  receivedzip <- tempfile()
  writeBin(f[[1]], receivedzip, useBytes = TRUE)
  final_data<-list("vector")
  list_of_csvs<-utils::unzip(receivedzip,list=TRUE)[,1]
  for (i in 1:length(list_of_csvs)) {
    conn <- unz(receivedzip, list_of_csvs[i])
    final_data[[i]] <- read.table(conn, sep=",",header=T)
  }
  unlink(receivedzip)

  tmp <- paste0("/home/data/", stringi::stri_rand_strings(1, 7, pattern = "[A-Za-z0-9]"))
  while (file.exists(tmp)) {
    tmp <- paste0("/home/data/", stringi::stri_rand_strings(1, 7, pattern = "[A-Za-z0-9]"))
  }

  dir.create(tmp)
  dir.create(file.path(tmp, "wd"))
  wd <- file.path(tmp, "wd")

  zipfile <- paste0("/home/data/", stringi::stri_rand_strings(1, 10, pattern = "[A-Za-z0-9]"), ".zip")
  while (file.exists(zipfile)) {
    zipfile <- paste0("/home/data/", stringi::stri_rand_strings(1, 10, pattern = "[A-Za-z0-9]"), ".zip")
  }

  ta <- final_data[[1]]
  tb <- final_data[[2]]
  tc <- final_data[[3]]

  # Processing which produces a number of files within the directory "wd" / code omitted

  zip::zip(zipfile, "wd", root = tmp)
  unlink(wd, recursive = TRUE)
  val <- readBin(zipfile, "raw", n=file.info(zipfile)$size)
  unlink(zipfile)
  as_attachment(val, "results.zip")
}

Error code

Error in file(open = "w+b", encoding = "UTF-8") :
cannot open the connection
Calls: -> file
In addition: Warning message:
In file(open = "w+b", encoding = "UTF-8") :
cannot open file '/tmp/Rtmpa4GHwN/Rf17deb5ac8': No such file or directory

Tasks

  1. type: question
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

1 participant