nx10 / httpgd

Asynchronous http server graphics device for R.
https://nx10.github.io/httpgd
GNU General Public License v2.0
368 stars 19 forks source link

R session crashes because of httpgd and grDevices::dev.capabilities() #122

Closed EdoardoCostantini closed 4 months ago

EdoardoCostantini commented 1 year ago

Describe the bug

I run the command:

grDevices::dev.capabilities()

the session stops and returns the following output:

*** caught segfault ***
address 0x0, cause 'memory not mapped'

Traceback:
 1: grDevices::dev.capabilities()

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection: 

I'm interested in this because a package I use uses this in a plotting function.

I've narrowed down the problem to httpgd because I reinstalled R from scratch, and if I install/remove httpgd, the problem appears/disappears respectively.

To Reproduce

Expected behavior

The output should be something like

$semiTransparency
[1] TRUE

$transparentBackground
[1] "semi"

$rasterImage
[1] "yes"

$capture
[1] TRUE

$locator
[1] TRUE

$events
character(0)

$patterns
[1] NA

$clippingPaths
[1] NA

$masks
[1] NA

$compositing
[1] FALSE

$transformations
[1] FALSE

$paths
[1] FALSE

Environment

mihaiconstantin commented 1 year ago

@nx10, to chip in on this, it seems related to httpgd changing the default graphics device.

For instance, with httpgd installed, the device is handeled via httpgd::hgd.

getOption("device")
# function(...) {
#    httpgd::hgd(
#      silent = TRUE
#    )
#    .vsc$request("httpgd", url = httpgd::hgd_url())
#  }

grDevices::dev.capabilities()
#  *** caught segfault ***
# address 0x0, cause 'invalid permissions'

However, after, for instance:

options(device = "png")

the call to grDevices::dev.capabilities() appears to wrok.

nx10 commented 1 year ago

Hi!

this has been fixed in the development version for a while (see #119)

You can install it directly via:

remotes::install_github("nx10/httpgd")

Let me know of this solves it for you.

We are currently blocked from making a new CRAN release because of a small memory leak in the webserver library (should be un-noticable).

I will keep this issue open until the fixed CRAN version is released.

mihaiconstantin commented 1 year ago

Oh, yes, now I remember—you mentioned about the CRAN release in https://github.com/REditorSupport/vscode-R/issues/1227#issuecomment-1286892349. Calling grDevices::dev.capabilities() seems to work well with the devel version!

nx10 commented 1 year ago

Yes it's a bit annoying but there is not really a great C++ http server library out there that's easy to integrate with R. Even rstudio (i.e. shiny etc.) use http-parser which is written in C and unmaintained for years now (and might be vulnerable to attacks).

Moving forward I think it might make sense to migrate to a Rust implementation. There is a number of well maintained active http libraries there. With the split of httpgd and unigd with a C API in between I have also basically prepared for this happening. But there is still some questions left whether CRAN will like this: https://github.com/r-rust/hellorust/issues/12

EdoardoCostantini commented 1 year ago

Hi!

this has been fixed in the development version for a while (see #119)

You can install it directly via:

remotes::install_github("nx10/httpgd")

Let me know of this solves it for you.

We are currently blocked from making a new CRAN release because of a small memory leak in the webserver library (should be un-noticable).

I will keep this issue open until the fixed CRAN version is released.

It works with this version! Thanks so much.

nx10 commented 4 months ago

Fixed in the newest release