Muhammad Hamza Altaf
Muhammad Hamza Altaf

Reputation: 117

Rails 4.2 app doesn't respond after 2-3 hours IDLE time on virtual private server

I am trying to setup my virtual private server on upcloud. I am using PUMA 4.3 with ruby 2.4.2 and rails 4.2.8. My Puma Configurations are

threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count

preload_app!

rackup      DefaultRackup
port        ENV['PORT']     || 3000
environment ENV['RACK_ENV'] || 'development'

on_worker_boot do
  # Worker specific setup for Rails 4.1+
  # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
  ActiveRecord::Base.establish_connection
end

My Nginx configuration is

        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 36000s;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

Lastly my example.com.conf file is

upstream my_app {
  server unix:///var/run/my_app.sock;
}

server {
  listen 80;
  server_name 94.237.52.251:443; # change to match your URL
  root /soop/soup; # I assume your app is located at that location

  location / {
    proxy_pass http://94.237.52.251:443; # match the name of upstream directive which is defined above
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

  location ~* ^/assets/ {
    # Per RFC2616 - 1 year maximum expiry
    expires 1y;
    add_header Cache-Control public;

    # Some browsers still send conditional-GET requests if there's a
    # Last-Modified header or an ETag header even if they haven't
    # reached the expiry date sent in the Expires header.
    add_header Last-Modified "";
    add_header ETag "";
    break;
  }
}

I have to restart rails server after every 15-20 mins of idle time, or everytime after I get disconnected from my VPS otherwise, browser shows me either 94.237.52.251 took too long to respond. OR Currently unable to handle this request. HTTP ERROR 500 I am facing this issue for a week now. Kindly help me out.

Upvotes: 2

Views: 78

Answers (1)

Benjamin Harel
Benjamin Harel

Reputation: 2946

Change your keepalive_timeout 36000s; to 75s

Upvotes: 1

Related Questions