rstudio / blogdown

Create Blogs and Websites with R Markdown
https://pkgs.rstudio.com/blogdown/
1.73k stars 335 forks source link

Hugo server stops when knitting while running serve_site() #492

Closed andrewheiss closed 4 years ago

andrewheiss commented 4 years ago

In the latest version of blogdown (856b50bba9479156fe5c031632d71b98f71f2285), the Hugo server stops working after knitting a file if blogdown.serve_site.startup and blogdown.knit.on_save are both set to FALSE in the options.

Here's how to recreate the bug (can't do a single reprex here since it involves multiple steps):

  1. Make clean new site with blogdown::new_site()

  2. Add .Rprofile to the project folder with this content:

options(
  blogdown.serve_site.startup = FALSE,  # automatically serve the site on RStudio startup
  blogdown.knit.on_save = FALSE  # automatically knit Rmd on save
)
  1. Restart R so that it picks up the new options and doesn't automatically start the server

  2. Run either blogdown:::serve_site() (or use RStudio add-in menu) to start the server (or with blogdown:::preview_site())

  3. Edit one of the default R Markdown files and knit with ⌘⇧K (or button in RStudio)

  4. Server at localhost:4321 (or whatever port the daemon is using) silently stops:

image

Here's my session info:

R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.6, RStudio 1.4.869

Locale: en_US.UTF-8 / en_US.UTF-8 / en_US.UTF-8 / C / en_US.UTF-8 / en_US.UTF-8

Package version:
  base64enc_0.1.3  BH_1.72.0.3      blogdown_0.21.13 bookdown_0.21    digest_0.6.25   
  evaluate_0.14    glue_1.4.2       graphics_4.0.2   grDevices_4.0.2  highr_0.8       
  htmltools_0.5.0  httpuv_1.5.4     jsonlite_1.7.1   knitr_1.30       later_1.1.0.1   
  magrittr_1.5     markdown_1.1     methods_4.0.2    mime_0.9         promises_1.1.1  
  R6_2.4.1         Rcpp_1.0.5       rlang_0.4.8      rmarkdown_2.4.5  servr_0.19      
  stats_4.0.2      stringi_1.5.3    stringr_1.4.0    tinytex_0.26     tools_4.0.2     
  utils_4.0.2      xfun_0.18        yaml_2.2.1      

Hugo version: 0.67.1

By filing an issue to this repo, I promise that

yihui commented 4 years ago

I was able to reproduce it once, but was unable to reproduce it again no matter what I try. Does it work if you close and reopen the RStudio project?

andrewheiss commented 4 years ago

Ha, yeah, it's been so hard to nail down what's happening—I get it to reproduce like 70% of the time. Sometimes it happens with serve_site(), sometimes with preview_site(). I was closing and reopening RStudio completely each time too.

Is there a way to see the hugo server logs, or are those invisible? It would help pin down what's happening.

yihui commented 4 years ago

I have tried several times and was not able to reproduce it again.

How about setting these options in .Rprofile?

options(
  blogdown.use.processx = FALSE,
  xfun.bg_process.verbose = TRUE
)
yihui commented 4 years ago

You may also check if there are any other stray hugo processes running and try to kill them:

ps -A | grep 'hugo server'
andrewheiss commented 4 years ago

Oh good, I got an error message finally. Something is causing hugo to panic:

Change detected, rebuilding site.
2020-10-15 22:24:22.713 -0400
Source changed "/Users/andrew/Desktop/testing/content/post/2015-07-23-r-rmarkdown/index_files/figure-html/log-duration-histogram-1.png": CREATE
Source changed "/Users/andrew/Desktop/testing/content/post/2015-07-23-r-rmarkdown/index_files/figure-html/log-duration-before-after-histogram-1.png": CREATE
Total in 0 ms
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4af0326]

goroutine 16 [running]:
github.com/gohugoio/hugo/hugolib.(*pageMaps).withMaps(0x0, 0xc000f8f2c0, 0x1, 0xc000f8f2b0)
    /private/tmp/hugo-20200315-13671-ect7cm/hugo-0.67.1/src/github.com/gohugoio/hugo/hugolib/content_map_page.go:772 +0x26
github.com/gohugoio/hugo/hugolib.(*pageMaps).walkBundles(0x0, 0xc000f8f2b0)
    /private/tmp/hugo-20200315-13671-ect7cm/hugo-0.67.1/src/github.com/gohugoio/hugo/hugolib/content_map_page.go:754 +0x61
github.com/gohugoio/hugo/hugolib.(*HugoSites).resetPageStateFromEvents(0xc0004d08c0, 0xc000fac8a0)
    /private/tmp/hugo-20200315-13671-ect7cm/hugo-0.67.1/src/github.com/gohugoio/hugo/hugolib/hugo_sites.go:908 +0x65
github.com/gohugoio/hugo/hugolib.(*Site).processPartial(0xc0000d5680, 0xc000f96840, 0xc000e35730, 0xc000f92f00, 0x4, 0x4, 0xc000e355c0, 0x40cb711)
    /private/tmp/hugo-20200315-13671-ect7cm/hugo-0.67.1/src/github.com/gohugoio/hugo/hugolib/site.go:1095 +0x955
github.com/gohugoio/hugo/hugolib.(*HugoSites).process(0xc0004d08c0, 0xc000f96840, 0xc000e35730, 0xc000f92d80, 0x4, 0x4, 0x69e3de0, 0x300000001)
    /private/tmp/hugo-20200315-13671-ect7cm/hugo-0.67.1/src/github.com/gohugoio/hugo/hugolib/hugo_sites_build.go:224 +0x99
github.com/gohugoio/hugo/hugolib.(*HugoSites).Build.func2.2()
    /private/tmp/hugo-20200315-13671-ect7cm/hugo-0.67.1/src/github.com/gohugoio/hugo/hugolib/hugo_sites_build.go:102 +0x64
runtime/trace.WithRegion(0x5c8bb60, 0xc000fac7b0, 0x584baad, 0x7, 0xc000e35758)
    /usr/local/Cellar/go/1.14/libexec/src/runtime/trace/annotation.go:137 +0xfe
github.com/gohugoio/hugo/hugolib.(*HugoSites).Build.func2(0x69e3de0, 0xc000f8f101)
    /private/tmp/hugo-20200315-13671-ect7cm/hugo-0.67.1/src/github.com/gohugoio/hugo/hugolib/hugo_sites_build.go:104 +0x162
github.com/gohugoio/hugo/hugolib.(*HugoSites).Build.func3()
    /private/tmp/hugo-20200315-13671-ect7cm/hugo-0.67.1/src/github.com/gohugoio/hugo/hugolib/hugo_sites_build.go:121 +0x2f
runtime/trace.WithRegion(0x5c8bb60, 0xc000fac7b0, 0x584ba4b, 0x7, 0xc000e35900)
    /usr/local/Cellar/go/1.14/libexec/src/runtime/trace/annotation.go:137 +0xfe
github.com/gohugoio/hugo/hugolib.(*HugoSites).Build(0xc0004d08c0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000fac780, 0x0, 0xc000f92d80, ...)
    /private/tmp/hugo-20200315-13671-ect7cm/hugo-0.67.1/src/github.com/gohugoio/hugo/hugolib/hugo_sites_build.go:123 +0x904
github.com/gohugoio/hugo/commands.(*commandeer).rebuildSites(0xc000867860, 0xc000f92d80, 0x4, 0x4, 0x0, 0x0)
    /private/tmp/hugo-20200315-13671-ect7cm/hugo-0.67.1/src/github.com/gohugoio/hugo/commands/hugo.go:741 +0x407
github.com/gohugoio/hugo/commands.(*commandeer).handleEvents(0xc000867860, 0xc000a6f200, 0xc000095fa0, 0xc000226c00, 0x20, 0x20, 0xc0000a1e30)
    /private/tmp/hugo-20200315-13671-ect7cm/hugo-0.67.1/src/github.com/gohugoio/hugo/commands/hugo.go:1106 +0x764
github.com/gohugoio/hugo/commands.(*commandeer).newWatcher.func1(0xc000a6f200, 0xc000867860, 0xc000095fa0, 0xc0000a1e30)
    /private/tmp/hugo-20200315-13671-ect7cm/hugo-0.67.1/src/github.com/gohugoio/hugo/commands/hugo.go:848 +0x1d8
created by github.com/gohugoio/hugo/commands.(*commandeer).newWatcher
    /private/tmp/hugo-20200315-13671-ect7cm/hugo-0.67.1/src/github.com/gohugoio/hugo/commands/hugo.go:844 +0x293
yihui commented 4 years ago

I know nothing about Go, so I can't do anything about it. Does this happen to other Hugo versions? You probably know that you can install multiple versions of Hugo now, and can switch among them via options(blogdown.hugo.version =) in .Rprofile.

andrewheiss commented 4 years ago

Upgrading to Hugo 0.76.5 seems to maybe have fixed it? I can't get it to trigger the crash like I did before. Now to fix my class website templates to handle all the breaking Hugo changes :)

yihui commented 4 years ago

Okay. Good to know that v0.67.1 might happen to be buggy. Once you find a version that works, you can pin the version in the option blogdown.hugo.version, so your website will not be affected by future Hugo updates.

andrewheiss commented 4 years ago

I've spent all morning working with auto-generation and there have been no crashes, so this can probably just get closed. Thanks!

yihui commented 4 years ago

Awesome! Thanks for the report and test!

yihui commented 4 years ago

FYI I just noticed that your section headers had double anchors (on mouse over): https://evalf20.classes.andrewheiss.com/example/rdd/ We had a mechanism to prevent that in rmarkdown, but it failed for some reason in your post. I'll look into it.

yihui commented 4 years ago

Should be fixed in the dev version of rmarkdown now:

remotes::install_github('rstudio/rmarkdown')
andrewheiss commented 4 years ago

Oh cool! I ended up adding this to an _output.yaml in all my content subdirectories to turn off rmarkdown's anchoring, since hugo-academic does it automatically:

blogdown::html_page:
  anchor_sections: false

Now I'll go remove those all :)

Also, rmarkdown auto adds the anchors in xaringan now too, so I added anchor_sections: false to the YAML in my sldies, since anchoring isn't really necessary there (but that's probably for a new issue in rmarkdown or xaringan)

yihui commented 4 years ago

I've disabled it in xaringan a couple of days ago: https://github.com/yihui/xaringan/commit/8c921da8001a58279ba9a3c057c67c182df6dff3 I've submitted new versions of rmarkdown and xaringan to CRAN this afternoon.

andrewheiss commented 4 years ago

Oh perfect! I'll take all those YAML options out now too :)