Hendrik
Hendrik

Reputation: 4929

Nginx + Passenger + Rails HTTP 499 in Logs after long running

I am having an issue with my NGINX+Passenger+Rails setup. One requests takes forever to run and is not canceled. I am not sure what is the reason, I have no errors in my error.log file.

Surprisingly if I switch to Puma as a webserver everything is working fine.

The code that causes the issue in my application is marked with a comment:

  def build_redirect_url
    raise ArgumentError.new("not implemented for provider") if checkout_settings[:package_provider] != "expedia_click_and_mix"
    opts = {
      :hotels            => [hotel],
      :from_date         => from_date,
      :to_date           => to_date,
      :from_airport_code => from_airport.code,
      :to_airport_code   => to_airport.code,
      :number_of_adults  => number_of_adults.to_i,
      :cache             => false,
      :piid              => checkout_settings[:unique_identifier]
    }
    # the below line never finishes. takes like 30 seconds
    searcher    = PackageKraken::ListKraken::HotelGrouper.new(opts)
    details_url = searcher.search.first.details_url
    filter_id   = search_filter_setting.id
    build_filter_redirect_url(filter_id, "expedia_click_and_mix", hotel.id, details_url)
  end

We never make it past the searcher = line. It seems the process dies before. So what I did is check my nginx log file for issues, but I only have this. Hoever it seems to have a 499 error code.

This is what I have in my log file:

79.236.111.56 - - [02/Nov/2016:14:28:30 +0100] "GET /packages/package_redirect_url?checkout_settings=%7B%22package_identifier%22%3A%22v5-8a5c783c4b614f2d8018117d4c7fa1f5-8-8-1%22
%2C%22package_provider%22%3A%22expedia_click_and_mix%22%7D&from_airport_id=b2ccff00-2186-482e-a74f-6892c8fd7f77&from_date=2016-11-09+01%3A00%3A00+%2B0100&hotel_id=14245&number_of
_adults=1&to_airport_id=aabc5cd4-36e6-45c9-b027-e0ed4b209414&to_date=2016-11-15+01%3A00%3A00+%2B0100 HTTP/1.1" 499 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWeb
Kit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"

Here is my site config for the website:

server {
  listen 80;
  server_name tripl.de www.tripl.de;
  return 301 https://$host$request_uri;
}

server {
  listen 443;
  server_name tripl.de;
  ssl on;
  ssl_certificate /etc/nginx/ssl/wildcard-cert.crt;
  ssl_certificate_key /etc/nginx/ssl/wildcard-cert.key;
  return 301 https://www.tripl.de$request_uri;
}

# Production server
server {
  proxy_connect_timeout       600;
  proxy_send_timeout          600;
  proxy_read_timeout          600;
  send_timeout                600;
  listen 443;
  server_name www.tripl.de;
  ssl on;
  ssl_certificate /etc/nginx/ssl/wildcard-cert.crt;
  ssl_certificate_key /etc/nginx/ssl/wildcard-cert.key;

  client_max_body_size 4G;
  keepalive_timeout 60;
  passenger_enabled on;
  root         /home/deployer/app_production/current/public;
  proxy_set_header        X-Forwarded-Proto https;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
     if ($request_method = 'OPTIONS') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        #
        # Custom headers and headers various browsers *should* be OK with but aren't
        #
        add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
        #
        # Tell client that this pre-flight info is valid for 20 days
        #
        add_header 'Access-Control-Max-Age' 1728000;
        add_header 'Content-Type' 'text/plain charset=UTF-8';
        add_header 'Content-Length' 0;
        return 204;
     }
     if ($request_method = 'POST') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
     }
     if ($request_method = 'GET') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
     }
}

}

And this is what I have in my passenger.conf:

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /home/deployer/.rbenv/shims/ruby;

Any ideas what could be wrong?

Thanks

Upvotes: 1

Views: 924

Answers (1)

Hendrik
Hendrik

Reputation: 4929

The problem was me using Celluloid in some area. Apparently passenger does not like spawning new threads.

Upvotes: 1

Related Questions