Closed richarddmorey closed 1 year ago
You cannot pre-load any packages or libraries that are not fork
-safe.
In this particular case the backtrace shows that knitr
(via rmarkdown
) is using the Quartz
device which is not fork-safe if CF has been initialized before, so in this case simply use fork-safe devices like Cairo, e.g. by adding
knitr::opts_chunk$set(dev="CairoPNG")
Thanks for that. Is there any way of telling beforehand whether an R package includes non-fork-safe functions?
I don't think so. Rule of thumb is that anything which involves system UI, jvm are likely not fork safe.
Issue
Under a very specific set of circumstances, RestRserve fails to serve a page on MacOS.
On macOS 12.6 (21G115), under these three conditions:
{promises}
is loaded{cli}
is installedrmarkdown::render
is called without having loaded the libraryThe server fails to give a response:
In the terminal running the server, we see
This does not seem to occur in Ubuntu 20.04.5 LTS.
Reproducing
To reproduce, I've created a repository here with a MRE: https://github.com/richarddmorey/testRestRserve
{renv}
:Removing
{cli}
, not loading{promises}
, or not callingrmarkdown::render
will eliminate the errors.Cause
I don't know enough to effectively debug this myself, given the fact that it seems to be an interaction between several packages. However, it is suggested here with a similar error in ruby that
My read of this is that it happens because of the anarchic nature of packages, and some forbidden initialization when
{rmarkdown}
loads after RestRserve forks off the process...? I don't understand why merely having{cli}
installed would cause a problem, though.Workaround
I've found that loading
{rmarkdown}
library at the start fixes the problem, but this might not be general enough.In this thread it is suggested to add an environment variable before starting the server:
I don't know if this has bad implications, but it seems to solve the problem.