passenger: Not Passenger Issue (was:Pure TCPServer doesn't connect with Passenger)

Issue report

Are you sure this is a bug in Passenger? No, it’s lack of documentation.

Question 1: What is the problem?

  • What is the expected behavior? - App should respond to incoming http requests
  • What is the actual behavior? - http requests via passenger+nginx is timeouted. While direct (by random port) has response
  • How can we reproduce it? Please try to provide a sample application (or Virtual Machine) demonstrating the issue. Otherwise, if we can’t reproduce it, we might have to ask you a number of followup questions or run certain commands to try and figure out the problem. - See code below

Question 2: Passenger version and integration mode:

  • open source nginx/1.10.2 Phusion_Passenger/5.1.2

Question 3: OS or Linux distro, platform (including version):

  • Debian 8.7, x86_64

Question 4: Passenger installation method:

Your answer: [ ] RubyGems + Gemfile [ ] RubyGems, no Gemfile [x] Phusion APT repo [ ] Phusion YUM repo [ ] OS X Homebrew [ ] source tarball

Question 5: Your app’s programming language (including any version managers) and framework (including versions):

  • ruby 2.4.1p111 (build from source), no rails, no sinatra, no thin, no other gems

Question 6: Are you using a PaaS and/or containerization? If so which one?

  • No

Question 7: Anything else about your setup that we should know?

Nginx File:

server {
  listen localhost:3045;
  server_name localhost;

  root /var/www/app/public;

  passenger_enabled on;
  passenger_app_type ruby;
  passenger_startup_file main.rb;
  passenger_sticky_sessions off;
}

Gemfile:

# frozen_string_literal: true
source "https://rubygems.org"

gem "passenger", ">= 5.0.25", require: "phusion_passenger/rack_handler"
gem "json"

After deploy I’ve ran (as app user):

su -s /bin/bash appuser
gem install passenger bundle --no-document
passenger-config build-native-support
bundle install --deployment --without development test

/var/www/app/main.rb:

server = TCPServer.new(0)
#!/usr/bin/env ruby
require 'rubygems'
require 'socket'
require 'json'

server = TCPServer.new(0)

loop do
  Thread.start(server.accept) do |socket|
    begin
      request = socket.gets

      if request.include? "/"
        _res = {}
        _res[:status] = "OK"
        response = _res.to_json
      else
        response = '{"error": "Nothing here!"}'
      end

      socket.print "HTTP/1.1 200 OK\r\n" +
                   "Content-Type: application/json; charset=UTF-8\r\n" +
                   "Content-Length: #{response.bytesize}\r\n" +
                   "Connection: close\r\n"

      socket.print "\r\n"
      socket.print response
      socket.close
    rescue Exception => e
      # puts e
    end
  end
end

/var/log/nginx/error.log:

App [pid] stdout:

About this issue

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

Most upvoted comments

I’m not sure what-all the first feature set will include.

Just that hijacking the socket shouldn’t be needed. Here’s a minimal example:

app = lambda do |env|
                [200, { "Content-Type" => "text/plain" }, ["ok"]]
              end
run app