rstudio / shiny-server

Host Shiny applications over the web.
https://rstudio.com/shiny/server
Other
723 stars 289 forks source link

"Failed to render error 500 page: Can't set headers after they are sent" error in log file. #266

Open bapoorva opened 7 years ago

bapoorva commented 7 years ago

I downloaded shiny-server and i am trying to configure it. But it keeps failing.

This is my shiny-server.config


# Instruct Shiny Server to run applications as the user "shiny"
run_as :HOME_USER;

# Define a server that listens on port 3838
server {
  listen 3838;

  # Define a location at the base URL
  location / {

    # Host the directory of Shiny Apps stored in this directory
    site_dir /srv/shiny-server;

    # Log all Shiny output to files in this directory
    log_dir /var/log/shiny-server;

    # When a user visits the base URL rather than a particular application,
    # an index of the applications available in this directory will be shown.
    directory_index on;
  }
}

I checked my firewall settings and gave this command


sudo ufw allow 3838/tcp

Yet I'm getting this error

An error has occurred

The application failed to start.

The application exited during initialization.

This is how my log file looks


[32m[2016-12-07 12:13:31.613] [INFO] shiny-server - Shiny Server v1.5.1.834 (Node.js v6.9.1)
[2016-12-07 12:13:31.615] [INFO] shiny-server - Using pidfile /var/run/shiny-server.pid
[2016-12-07 12:13:31.615] [INFO] shiny-server - Using config file "/etc/shiny-server/shiny-server.conf"
[2016-12-07 12:13:31.635] [WARN] shiny-server - Running as root unnecessarily is a security risk! You could be running more securely as non-root.
[2016-12-07 12:13:31.638] [INFO] shiny-server - Starting listener on 0.0.0.0:3838
[2016-12-07 12:28:12.088] [ERROR] shiny-server - Failed to render error 500 page: Can't set headers after they are sent.
[2016-12-07 12:28:12.101] [INFO] shiny-server - Created bookmark state directory: /var/lib/shiny-server/bookmarks
[2016-12-07 12:28:12.106] [INFO] shiny-server - Created user bookmark state directory: /var/lib/shiny-server/bookmarks/shiny
[2016-12-07 12:28:12.310] [INFO] shiny-server - Error getting worker: Error: The application exited during initialization.
[2016-12-07 12:47:10.230] [INFO] shiny-server - Error getting worker: Error: The application exited during initialization.
[2016-12-07 12:47:11.646] [INFO] shiny-server - Error getting worker: Error: The application exited during initialization.

What is going on here ? how do I fix this ?

fereshtehRS commented 7 years ago

@bapoorva The issue is most likely with run_as :HOME_USER; in your configuration. :HOME_USER: only applies to hosting models that run applications from user's directories. Please refer to this section of Admin Guide:

http://docs.rstudio.com/shiny-server/#home_user

If you want to use site_dir you need to define an actual user (by default shiny) as the run_as user.

Or you can use :HOME_USER: but change your hosting model to user_dirs. Please refer to this section of Admin Guide for more on this:

http://docs.rstudio.com/shiny-server/#let-users-manage-their-own-applications

bapoorva commented 7 years ago

I initially kept the default config and ran it as run_as shiny. Then I changed it to user. But it does not work. I got same error in the log file even after restarting.

If i change the hosting model to user_dirs like you mentioned, is says "page not found"

fereshtehRS commented 7 years ago

OK, there could be other thing wrong as well, but that was the first thing that needed to be fixed.

When you switch to using user_dirs the URL to access the application changes. For example assume this is your configuration:

server {
  listen 3838;
  location / {
    user_dirs;
  }
}

/home/username/ShinyApps/app1 (substitute actual username)

http://localhost:3838/username/app1 (substitute actual username)

Let's see if this works, or using site_dir with run_as shiny;.

bapoorva commented 7 years ago

Yes. I did that. my username is user. I switched to user_dirs using sudo opt/shiny-server/bin/deploy-example user-dirs, copied my app to ~/ShinyApps and used the url http://hostname:3838/user/app. It gave me a "page not found error"

Then I switched to site_dir using sudo opt/shiny-server/bin/deploy-example default and ran it with both run_as shiny and run_as user, this time using the url http://hostname:3838/Sample-Apps/app . A copy of the same app is present in the shiny-server dir. Both times, i got

An error has occurred
The application failed to start.
The application exited during initialization.

I checked my firewall. i have given all permissions. I am at a loss.

fereshtehRS commented 7 years ago

preserve_logs true;