jeroen / mongolite

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

Trying to reproduce "Error in mongo_get_default_database(client) : Client has been destroyed" #214

Closed Tazinho closed 3 years ago

Tazinho commented 3 years ago

Edit: Unfortunately the example below doesn't reproduce the error anymore.

I am having a similar issue as posted in #178, #162 and #184: "Error in mongo_get_default_database(client) : Client has been destroyed." It appears when I "use" mongo in different processes or sequentially write to it and I have no idea how to avoid it.

It's not straight forward to reproduce, but it gets relatively reliable triggered with the following code.

library(mongolite)
mongo("iris")$drop()
mongo("iris")$insert(iris)

for (i in 1:100000) {
  if (!i %%1000) {print(i)}
  # mongo()$disconnect()
  mongo("iris")$insert(iris[1, ])
}
[1] 1000
[1] 2000
[1] 3000
[1] 4000
[1] 5000
[1] 6000
[1] 7000
[1] 8000
[1] 9000
[1] 10000
[1] 11000
[1] 12000
[1] 13000
[1] 14000
[1] 15000
[1] 16000
[1] 17000
[1] 18000
[1] 19000
[1] 20000
[1] 21000
[1] 22000
[1] 23000
[1] 24000
[1] 25000
[1] 26000
[1] 27000
[1] 28000
[1] 29000
[1] 30000
[1] 31000
[1] 32000
[1] 33000
[1] 34000
[1] 35000
[1] 36000
[1] 37000
[1] 38000
[1] 39000
[1] 40000
[1] 41000
[1] 42000
[1] 43000
[1] 44000
[1] 45000
[1] 46000
[1] 47000
[1] 48000
[1] 49000
[1] 50000
[1] 51000
[1] 52000
[1] 53000
[1] 54000
[1] 55000
[1] 56000
[1] 57000
[1] 58000
[1] 59000
[1] 60000
[1] 61000
[1] 62000
[1] 63000
[1] 64000
[1] 65000
[1] 66000
[1] 67000
[1] 68000
[1] 69000
[1] 70000
Error in mongo_get_default_database(client) : Client has been destroyed.

> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.1 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C          
[3] LC_TIME=C.UTF-8        LC_COLLATE=C.UTF-8    
[5] LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
[7] LC_PAPER=C.UTF-8       LC_NAME=C             
[9] LC_ADDRESS=C           LC_TELEPHONE=C        
[11] LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

attached base packages:
  [1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
  [1] mongolite_2.2.1

loaded via a namespace (and not attached):
  [1] compiler_4.0.3 tools_4.0.3    tinytex_0.28   jsonlite_1.7.2
[5] xfun_0.20      openssl_1.4.3  askpass_1.1   
jeroen commented 3 years ago

Thanks! I'll try to reproduce this

Tazinho commented 3 years ago

Sorry, I was a bit too quick. After I posted here, I reran the code above several times and couldn't reproduce the error anymore...(I edited the post accordingly, but hope to come up with a better reprex at some point...).

jeroen commented 3 years ago

Don't worry I found the problem I think

jeroen commented 3 years ago

I think it is fixed now...

jeroen commented 3 years ago

No it isn't :(

jeroen commented 3 years ago

OK I think this really fixes it: https://github.com/jeroen/mongolite/commit/a3cbda0af70a4aa3b4584e506238b35df9db3c0b

Tazinho commented 3 years ago

Many thanks for your quick support!

jeroen commented 3 years ago

I've sent it off to CRAN. I really hope this problem is finally fixed.

Tazinho commented 3 years ago

I think so. Updating to the current DEV-branch seems to have solved this error for me.