jeroen / mongolite

Fast and Simple MongoDB Client for R
https://jeroen.github.io/mongolite/
284 stars 64 forks source link

Using mongolite connection in a forked process ? #256

Closed ncullen93 closed 7 months ago

ncullen93 commented 7 months ago

Is it possible to create a mongo connection in a forked process? It seems to give an error. The only reprex I have is based on the RestRserve api framework.

library(RestRserve)
library(mongolite)

fetch_models_handler <- function(req, res) {
  conn <- mongolite::mongo(collection, db, url)
 # then, eventually make a find() call and disconnect
 # adding conn$disconnect() doesnt help
}

app = Application$new(
  content_type = "application/json"
)

app$add_get(
  path = "/fetchModels",
  FUN = fetch_models_handler
)

backend = BackendRserve$new()
backend$start(app, http_port = 8080)

This framework creates a forked process for each request, hence the error.

It leads to this error:

objc[2671]: +[NSNumber initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.