rstudio / shiny

Easy interactive web applications with R
https://shiny.posit.co/
Other
5.35k stars 1.87k forks source link

getwd() seems to return NULL occasionally on shiny server #2685

Open stefanoborini opened 4 years ago

stefanoborini commented 4 years ago

Posted also on rstudio/shiny-server#408 as I am unsure if it's a shiny or shiny server problem at this stage.

Not sure if this is due to my organisation configuration of shiny server, but in my deployment I attempt to retrieve the current directory with getwd() at the very beginning of the app.R file. Occasionally, this returns NULL, but I've seen it return the actual path to the deployed application occasionally. I was unable to identify a pattern, but you might have some ideas.

More in general, is there a way to obtain the current deployment root path?

wch commented 4 years ago

That's very strange. Looking at the R source code, it looks like getwd() calls the C function getcwd(), which can fail for a number of reasons, as described here: http://man7.org/linux/man-pages/man2/getcwd.2.html#ERRORS

https://github.com/wch/r-source/blob/6837d12f51028bde80347bb3c55230824eb5e039/src/main/util.c#L746

Is it possible that your application has a parent directory that the shiny user is not allowed to access? I'm thinking of this error:

EACCES: Permission to read or search a component of the filename was denied.

stefanoborini commented 4 years ago

@wch it is more likely that it's due to ENOENT, as it normally arises when I redeploy an application to the shiny server, which deletes the directory. However, this would only happen if shiny server spawns a process associated to that directory (plausible) and then keeps that process alive while also reparsing the newly deployed code with the exact same process.

This seems implausible to me because I also tried to ensure that removing the directory would show me a "not found" message, then deploying the application. I would assume this ensures the subprocess terminates. Yet, the error occurs anyway.

But at this point I suspect shiny server process lifecycle is more under scrutiny for this one.