puma: Puma seems to time out on returning a response

System configuration

Puma --> 3.9.1 JRuby --> 9.1.12.0 Rails --> 4.2.8 nginx --> 1.12.0 Red Hat Enterprise Linux Server release 6.9 (Santiago) java version “1.8.0_66” Java™ SE Runtime Environment (build 1.8.0_66-b17) Java HotSpot™ 64-Bit Server VM (build 25.66-b17, mixed mode)

Puma config


#!/usr/bin/env puma

directory '/opt/verto/mindmerge-demo/current'
rackup "/opt/verto/mindmerge-demo/current/config.ru"
environment 'production'

tag ''

pidfile "/opt/company/demo/shared/tmp/pids/puma.pid"
state_path "/opt/company/demo/shared/tmp/pids/puma.state"
stdout_redirect '/opt/company/demo/current/log/puma.error.log', '/opt/company/demo/current/log/puma.access.log', true

threads 8,16

bind 'unix:///opt/company/demo/shared/tmp/sockets/puma.sock'

#preload_app!

on_restart do
  puts 'Refreshing Gemfile'
  ENV["BUNDLE_GEMFILE"] = "/opt/company/demo/current/Gemfile"
end

Puma started with: bundle exec puma -e production -d -C /opt/company/demo/shared/puma.rb

nginx config:

upstream demo {
  server unix:///opt/company/demo/shared/tmp/sockets/mindmerge-puma.sock;
}

server {
      listen   80;
      server_name demo.mindmergeapp.com;
      ## redirect http to https ##
      rewrite        ^ https://demo.mindmergeapp.com$request_uri? permanent;
}

server {
  listen 443 ssl;
  server_name demo.mindmergeapp.com; # change to match your URL
  root /opt/company/demo/current/public;

  ssl on;
  ssl_certificate /etc/ssl/app/SSL.crt;
  ssl_certificate_key /etc/ssl/app/app.net.key;

  access_log /var/log/nginx/nginx.demo.ourpp.com.access.log;
  error_log /var/log/nginx/nginx.demo.ourapp.com.error.log;

  location / {
    proxy_pass http://demo; # 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;
    proxy_redirect off;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }

Steps to reproduce

  1. Rails app on JRuby with puma as app server

  2. Configure nginx as a reverse proxy. Set up forward of HTTP traffic to HTTPS. Puma is bound to a socket file and nginx points to it correctly.

  3. Tail production.log and nginx access/error logs.

Expected behavior

I expect the request to complete without any problems. There is no traffic on the server other than me testing.

Actual behavior

Even though the Rails app responds right away to the request and logs the response to the production.log, there is no view rendered. Only a 504 - Gateway Timeout is shown, both in the browser and nginx logs.

Here’s an example request/response from logs:

==> log/production.log <==
# Rails log

Started GET "/" for 99.234.241.234 at 2017-07-07 23:02:47 -0400
Processing by MccsController#index as HTML
  User Load (4.1ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 2  ORDER BY `users`.`id` ASC LIMIT 1
  Setting Load (1.8ms)  SELECT  `settings`.* FROM `settings`  ORDER BY `settings`.`id` ASC LIMIT 1
  CACHE (0.2ms)  SELECT  `settings`.* FROM `settings`  ORDER BY `settings`.`id` ASC LIMIT 1
  Mcc Load (2.1ms)  SELECT  `mccs`.* FROM `mccs` WHERE `mccs`.`id` = 0 LIMIT 1
  Mcc Load (3.0ms)  SELECT `mccs`.* FROM `mccs` INNER JOIN `mccs_users` ON `mccs`.`id` = `mccs_users`.`mcc_id` WHERE `mccs_users`.`user_id` = 2
  Rendered mccs/index.html.erb within layouts/application (93.9ms)
  Role Load (2.2ms)  SELECT  `roles`.* FROM `roles` WHERE `roles`.`name` = 'admin' LIMIT 1
  Role Exists (2.0ms)  SELECT  1 AS one FROM `roles` INNER JOIN `users_roles` ON `roles`.`id` = `users_roles`.`role_id` WHERE `users_roles`.`user_id` = 2 AND `roles`.`id` = 3 LIMIT 1
  Rendered layouts/_header.html.erb (100.6ms)
  Rendered layouts/_mcc_nav.html.erb (4.7ms)
  Rendered registrations/_edit.html.erb (24.4ms)
  Rendered layouts/_footer.html.erb (3.0ms)
Completed 200 OK in 989ms (Views: 331.9ms | ActiveRecord: 44.2ms)
# nginx access and error logs
==> /var/log/nginx/nginx.demo.ourapp.com.error.log <==
2017/07/07 23:03:47 [error] 7559#7559: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 99.234.241.234, server: demo.ourapp.com, request: "GET / HTTP/1.1", upstream: "http://unix:///opt/company/demo/shared/tmp/sockets/puma.sock/", host: "demo.ourapp.com"

==> /var/log/nginx/nginx.demo.ourapp.com.access.log <==
99.234.241.234 - - [07/Jul/2017:23:03:47 -0400] "GET / HTTP/1.1" 504 585 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"

Any help is appreciated.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (3 by maintainers)

Most upvoted comments

I think your UNIX address for the upstream is wrong. I don’t know why you have three slashes after unix:. Docs say just one is necessary, e.g. unix:/tmp/backend2;

In any case, this is a problem with your NGINX config, not Puma.

that link is a 404: https://github.com/puma/puma/blob/master/examples/config.rb#L181-L188

I was interested because my app times out when people are uploading a large image in a post request. But yes the sensible answer would be to process the image upload in a background task. Still I am interested in that link.

It’s a JRuby problem, @poc7667. See the #1375 for details on how to solve it.