Closed bersbersbers closed 2 years ago
It is also generally worth noting that I can't seem to reproduce this with an old version of tidyr that used Rcpp, but soon after the switch to cpp11 this starts happening. It has proved to be difficult to isolate though
I so far have been unable to reproduce this either on macOS or in a Ubuntu Docker container.
The behavior looks like either stack corruption or a protection failure, but it is going to be difficult to track down unless I can reproduce it myself.
I had hoped that an example that fails on Windows and Linux is universal, but it seems not. But I can provider some further information.
Windows is Windows 10 21H2, R 4.1.1 WSL is Ubuntu 20.04, R 4.1.1. Linux is OpenSUSE Leap 15.2
Here's a session info from WSL (before the loop):
> sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.3 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 LC_TIME=C.UTF-8
[4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
[7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_1.0.7 tidyr_1.1.4 fansi_0.5.0 utf8_1.2.2
[5] crayon_1.4.1 dplyr_1.0.7 R6_2.5.1 lifecycle_1.0.1
[9] magrittr_2.0.1 zip_2.2.0 pillar_1.6.4 stringi_1.7.5
[13] rlang_0.4.12 vctrs_0.3.8 generics_0.1.0 ellipsis_0.3.2
[17] openxlsx_4.2.4 tools_4.1.1 glue_1.4.2 purrr_0.3.4
[21] compiler_4.1.1 pkgconfig_2.0.3 tidyselect_1.1.1 tibble_3.1.5
What else could be helpful for me to provide?
I've managed to reproduce this without tidyr
Open up an R Console and run this and for me it segfaults most of the time (running this in RStudio won't immediately crash it, but it often makes further processing hang and eventually segfault somewhere)
invisible(gctorture2(50))
cpp11::cpp_function(
'
cpp11::list fn_cpp() {
cpp11::writable::list out(4);
return out;
}
'
)
fun2 <- function() {
openxlsx::write.xlsx(as.data.frame(1), tempfile())
}
y <- fn_cpp()
fun2()
while (TRUE) {
print(fn_cpp())
}
@DavisVaughan great job. I had to install.packages("decor")
, but now I could confirm the segmentation fault on WSL (pasting the code into the R console on the shell) on the first try (not on the second, though). On native Linux, there is not segfault either as far as I have tried (a few times), but I guess the most important point is to have one less package to care about. I wonder when we find/if there is an example without openxlsx
.
Ok, I have finally be able to reproduce this, I think the problem was I was using R 4.1.0 rather than 4.1.1+, and I didn't encounter the crash with that version.
I ran my example above with gctorture2(5)
and it seems to be working, so I think that was it?
Test log:
devtools::install_github("r-lib/cpp11")
install.packages("tidyr")
devtools::install_github("https://github.com/r-lib/cpp11/pull/245")
install.packages("tidyr")
install.packages("cpp11")
install.packages("tidyr")
This looks pretty consistent in that installing #245 and reinstalling tidyr
fixes the issue until tidyr
is rebuilt with another version of cpp11
not including #245. Looks like a weeks-long saga comes to an end, thanks to everyone involved 🚀
Tests using my original code took a bit longer, so here is the condensed log:
install.packages("cpp11"); install.packages("tidyr")
devtools::install_github("https://github.com/r-lib/cpp11/pull/245"); install.packages("tidyr")
devtools::install_github("r-lib/cpp11"); install.packages("tidyr")
Thanks again!
Open R and copy-and-paste this:
gives
I can repro the problem on five OSes: 1 x OpenSUSE Leap 15.2, 2 x Windows 10, and 2 x Ubuntu 20.04 in Windows 10 WSL.
This issue has a long history with me (https://github.com/tidyverse/tidyr/issues/1163, https://github.com/ycphs/openxlsx/issues/267, tidyverse/ggplot2#4635, rstudio/rmarkdown#2229, thomasp85/patchwork#278).
After bisecting CRAN releases of
tidyr
, I finally bisectedcpp11
from GitHub and found 087861f9ee2383d717255ecb0487e4b297808c49 as the first bad commit. More details below.I am still not convinced that cpp11 is the culprit, but developers of
openxlsx
andtidyr
, while being able to reproduce the issue, don't find the source in their code base, either. So maybe people here have an idea.