languageserver icon indicating copy to clipboard operation
languageserver copied to clipboard

Segfault: memory not mapped, with renv

Open jolars opened this issue 3 years ago • 12 comments

Issue

I am getting the following error running VS Code R with the vscode-R and R-LSP extensions with a project using the renv package.

[2021-06-02 13:00:30.396] parse session init error 1 {
  "code": 501,
  "message": "R session crashed with exit code -11",
  "result": null,
  "stdout": "",
  "stderr": "\n *** caught segfault ***\naddress 0x7fa2bb756a40, cause 'memory not mapped'\n\nTraceback:\n 1: pxlib$write_fd(as.integer(3), data)\n 2: eval(quote({    pxlib <- as.environment(\"tools:callr\")$`__callr_data__`$pxlib    code_ <- 201    fd_ <- 3    text_ <- \"ready to go\"    data <- paste0(code_, \" 0 \", text_, \"\\n\")    pxlib$write_fd(as.integer(3), data)}), new.env())\n 3: eval(quote({    pxlib <- as.environment(\"tools:callr\")$`__callr_data__`$pxlib    code_ <- 201    fd_ <- 3    text_ <- \"ready to go\"    data <- paste0(code_, \" 0 \", text_, \"\\n\")    pxlib$write_fd(as.integer(3), data)}), new.env())\n 4: eval(expr, p)\n 5: eval(expr, p)\n 6: eval.parent(substitute(eval(quote(expr), envir)))\n 7: local({    pxlib <- as.environment(\"tools:callr\")$`__callr_data__`$pxlib    code_ <- 201    fd_ <- 3    text_ <- \"ready to go\"    data <- paste0(code_, \" 0 \", text_, \"\\n\")    pxlib$write_fd(as.integer(3), data)})\nAn irrecoverable exception occurred. R is aborting now ...\n",
  "error": {
    "message": "R session crashed with exit code -11"
  }
}

It enters an endless loop and ends up flooding my CPU.

Steps to reproduce

  1. Install VS Code and the vcsode-r and vscode-r-lsp extensions
  2. Open a new folder in VS Code
  3. Open an R console and attach the vcode-r package
  4. run renv::init() followed by install.packages("languageserver")
  5. restart R

This happens both with radian and R as consoles.

System information

VS Code

Version: 1.56.2
Commit: 054a9295330880ed74ceaedda236253b4f39a335
Date: 2021-05-12T16:45:26.313Z
Electron: 12.0.4
Chrome: 89.0.4389.114
Node.js: 14.16.0
V8: 8.9.255.24-electron.0
OS: Linux x64 5.12.8-300.fc34.x86_64

sessionInfo()

R version 4.0.5 (2021-03-31)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Fedora 34 (Workstation Edition)

Matrix products: default
BLAS/LAPACK: /usr/lib64/libflexiblas.so.3.0

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

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

loaded via a namespace (and not attached):
[1] compiler_4.0.5 tools_4.0.5    jsonlite_1.7.2 rlang_0.4.11   renv_0.13.2 

jolars avatar Jun 02 '21 11:06 jolars

Does it work when renv is not used?

randy3k avatar Jun 02 '21 12:06 randy3k

Yes. When disabling renv it works fine.

Interestingly, I have another folder that uses renv where the issue does not occur. I have not so far been able to figure out why this doesn't happen with that project, however.

jolars avatar Jun 02 '21 12:06 jolars

I noticed that commenting out source("renv/activate.R") in the .Rprofile once the errors start appearing stops the segfault loop.

Perhaps this is a naive idea, but would it be possible to invoke some exception to handling the renv activate.R function (unless there's actually some real bug here)?

By the way, is anyone else able to reproduce this?

jolars avatar Jun 11 '21 09:06 jolars

I guess one of the packages was not installed probably. Just removed all the renv related files and try again.

randy3k avatar Jun 11 '21 14:06 randy3k

No, I just wiped R from the computer (including renv cache and all packages), and running the steps to reproduce above, I end up with exactly the same segfault.

jolars avatar Jun 11 '21 15:06 jolars

I can reproduce this.

> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Pop!_OS 21.04

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3
LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3

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

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

loaded via a namespace (and not attached):
[1] compiler_4.1.0 tools_4.1.0    renv_0.13.2   

VS Code

Version: 1.58.2
Commit: c3f126316369cd610563c75b1b1725e0679adfb3
Date: 2021-07-14T22:30:16.440Z
Electron: 12.0.13
Chrome: 89.0.4389.128
Node.js: 14.16.0
V8: 8.9.255.25-electron.0
OS: Linux x64 5.11.0-7620-generic

The languageserver reports:

[2021-07-20 16:04:07.786] parse session init error 1 {
  "code": 501,
  "message": "R session crashed with exit code -11",
  "result": null,
  "stdout": "",
  "stderr": "\n *** caught segfault ***\naddress 0x7fae8ed14a30, cause 'memory not mapped'\n\nTraceback:\n 1: pxlib$write_fd(as.integer(3), data)\n 2: eval(quote({    pxlib <- as.environment(\"tools:callr\")$`__callr_data__`$pxlib    code_ <- 201    fd_ <- 3    text_ <- \"ready to go\"    data <- paste0(code_, \" 0 \", text_, \"\\n\")    pxlib$write_fd(as.integer(3), data)}), new.env())\n 3: eval(quote({    pxlib <- as.environment(\"tools:callr\")$`__callr_data__`$pxlib    code_ <- 201    fd_ <- 3    text_ <- \"ready to go\"    data <- paste0(code_, \" 0 \", text_, \"\\n\")    pxlib$write_fd(as.integer(3), data)}), new.env())\n 4: eval(expr, p)\n 5: eval(expr, p)\n 6: eval.parent(substitute(eval(quote(expr), envir)))\n 7: local({    pxlib <- as.environment(\"tools:callr\")$`__callr_data__`$pxlib    code_ <- 201    fd_ <- 3    text_ <- \"ready to go\"    data <- paste0(code_, \" 0 \", text_, \"\\n\")    pxlib$write_fd(as.integer(3), data)})\nAn irrecoverable exception occurred. R is aborting now ...\n",
  "error": {
    "message": "R session crashed with exit code -11"
  }
}

jmbuhr avatar Jul 20 '21 14:07 jmbuhr

A colleague of mine is also experiencing this. I'm not however, working on the same server and repository.

adamaltmejd avatar Oct 14 '21 07:10 adamaltmejd

Looks like it is a bug of callr? Let me try if I could reproduce it.

renkun-ken avatar Oct 14 '21 07:10 renkun-ken

Ah good catch, maybe its callr that needs a reinstall.

adamaltmejd avatar Oct 14 '21 07:10 adamaltmejd

Does it occur with the latest dev of callr?

renkun-ken avatar Oct 14 '21 07:10 renkun-ken

Tried for a while but cannot reproduce it.

renkun-ken avatar Oct 14 '21 07:10 renkun-ken

Seems problem was related to vscode, disappeared after following these instructions: https://code.visualstudio.com/docs/remote/troubleshooting#_cleaning-up-the-vs-code-server-on-the-remote

adamaltmejd avatar Oct 14 '21 09:10 adamaltmejd