Blogdown serve-site() aborting R session

blogdown

#21

Thanks! Does this crash RStudio?

httpuv::startDaemonizedServer(
  '127.0.0.1', p <- servr:::random_port(),
  list(call = function(req) list(
    status = 200L, body = 'Hello world!',
    headers = list('Content-Type' = 'text/plain')
  ))
)
readLines(paste0('http://127.0.0.1:', p), warn = F)

#22

@yihui

That works fine, too

However, my issue is no longer the crashing which appears to be solved by your suggestion above
It's that I'm concerned that my hugo_build is building such a small index.xmland the location of the html files for each post


#23

The output from the initial command for me is similar:

[1] "211126576"
[1] "Hello world!"
[1] 0

The subsequent block of code doesn't crash either -- not at first. If I run it several times (realizing I'm creating multiple servers), it crashes.

After some more investigation, I'm suspecting there is something that isn't thread safe and create a race condition when multiple servers are running. The following code will reliably crash R while reading from the second server:

httpuv::startDaemonizedServer(
  '127.0.0.1', p <- servr:::random_port(),
  list(call = function(req) list(
    status = 200L, body = 'Hello world!',
    headers = list('Content-Type' = 'text/plain')
  ))
)
res <- replicate(100, readLines(paste0('http://127.0.0.1:', p), warn = F))

httpuv::startDaemonizedServer(
  '127.0.0.1', p <- servr:::random_port(),
  list(call = function(req) list(
    status = 200L, body = 'Hello world!',
    headers = list('Content-Type' = 'text/plain')
  ))
)
res <- replicate(100, readLines(paste0('http://127.0.0.1:', p), warn = F))

That explains part of why I was getting inconsistent results with daemonized servers.


#24

Thanks! That is helpful to me, although I have no idea how to fix this problem. A blind shot in the dark is to test the devel version of httpuv if you have Rtools installed: https://github.com/rstudio/httpuv (which includes a newer version of libuv).

if (!require("devtools")) install.packages("devtools")
devtools::install_github("rstudio/httpuv")

#25

When your work devolves to dealing with race conditions in Windows, it may be time to run away...

Installing the devel version of httpuv made things worse in a very confusing manner. Even without repeating it, the first readLines statement hangs, then eventually produces ERROR: [on_request_read] connection reset by peer and aborts R. However, if I use Chrome to access the server, it works fine.

It also doesn't solve the original problem, in that if I create two servers and connect to one with Chrome, refreshing several times crashes R.

I highly recommend you find someone that you can argue should care about this more than you and then take my original advice to run. :wink:


#26

Okay, I'll run as quickly as I can :joy:, while Cc'ing @jcheng @winston