kigster / puma-daemon

Puma (starting version 5) removed automatic demonization from the gem itself. This functionality was extracted to this gem, which supports Puma v5 and v6.
MIT License
37 stars 6 forks source link

uninitialized constant Puma::HAS_SSL (NameError) #3

Closed mpptx closed 3 years ago

mpptx commented 3 years ago

Hi there, I'm running Rails app with the following environment:

My puma.rb's content:

require 'puma/daemon'
daemonize

threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }
threads threads_count, threads_count
environment ENV.fetch('RAILS_ENV') { 'development' }

if ['production', 'staging'].include? ENV['RAILS_ENV']
  app_dir = File.expand_path("../..", __FILE__)

  bind "unix://#{app_dir}/tmp/sockets/puma.sock"
  pidfile "#{app_dir}/tmp/pids/puma.pid"
  state_path "#{app_dir}/tmp/pids/puma.state"
else
  port ENV.fetch('PORT') { 3000 }
end

plugin :tmp_restart

When I'll launch puma, the server starts normally. If I'll execute pumad, the following exception is thrown:

$ pumad
/Users/user/.rvm/gems/ruby-3.0.0/gems/puma-5.2.1/lib/puma/binder.rb:12:in `<module:Puma>': uninitialized constant Puma::HAS_SSL (NameError)
        from /Users/user/.rvm/gems/ruby-3.0.0/gems/puma-5.2.1/lib/puma/binder.rb:10:in `<top (required)>'
        from /Users/user/.rvm/gems/ruby-3.0.0/gems/puma-5.2.1/lib/puma/server.rb:11:in `require'
        from /Users/user/.rvm/gems/ruby-3.0.0/gems/puma-5.2.1/lib/puma/server.rb:11:in `<top (required)>'
        from /Users/user/.rvm/gems/ruby-3.0.0/gems/puma-5.2.1/lib/puma/runner.rb:3:in `require'
        from /Users/user/.rvm/gems/ruby-3.0.0/gems/puma-5.2.1/lib/puma/runner.rb:3:in `<top (required)>'
        from /Users/user/.rvm/gems/ruby-3.0.0/gems/puma-daemon-0.1.1/lib/puma/daemon.rb:3:in `require'
        from /Users/user/.rvm/gems/ruby-3.0.0/gems/puma-daemon-0.1.1/lib/puma/daemon.rb:3:in `<top (required)>'
        from /Users/user/.rvm/gems/ruby-3.0.0/gems/puma-daemon-0.1.1/exe/pumad:4:in `require'
        from /Users/user/.rvm/gems/ruby-3.0.0/gems/puma-daemon-0.1.1/exe/pumad:4:in `<top (required)>'
        from /Users/user/.rvm/gems/ruby-3.0.0/bin/pumad:23:in `load'
        from /Users/user/.rvm/gems/ruby-3.0.0/bin/pumad:23:in `<main>'
        from /Users/user/.rvm/gems/ruby-3.0.0/bin/ruby_executable_hooks:22:in `eval'
        from /Users/user/.rvm/gems/ruby-3.0.0/bin/ruby_executable_hooks:22:in `<main>'

Do you happen to know what causes this and how I can make it run correctly?

mpptx commented 3 years ago

@kigster could you please take a look at this? I'd really appreciate it :)

kigster commented 3 years ago

I'll take a look today.

But you like, try the following:

I suspect that ruby is not finding the constant because it's confused about which puma.rb the constant is defined

If this doesn't work,I'll take a look in a couple of hours .

mpptx commented 3 years ago

It still does not work. That's the content of puma.rb with your suggestions applied:

require 'puma'
require 'puma/daemon'
daemonize

threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }
threads threads_count, threads_count
environment ENV.fetch('RAILS_ENV') { 'development' }

if ['production', 'staging'].include? ENV['RAILS_ENV']
  app_dir = File.expand_path("../..", __FILE__)

  bind "unix://#{app_dir}/tmp/sockets/puma.sock"
  pidfile "#{app_dir}/tmp/pids/puma.pid"
  state_path "#{app_dir}/tmp/pids/puma.state"
else
  port ENV.fetch('PORT') { 3000 }
end

plugin :tmp_restart

The stacktrace I'm getting:

$ pumad -D
/opt/homebrew/lib/ruby/gems/3.0.0/gems/puma-5.2.1/lib/puma/binder.rb:12:in `<module:Puma>': uninitialized constant Puma::HAS_SSL (NameError)
        from /opt/homebrew/lib/ruby/gems/3.0.0/gems/puma-5.2.1/lib/puma/binder.rb:10:in `<top (required)>'
        from <internal:/opt/homebrew/Cellar/ruby/3.0.0_1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:/opt/homebrew/Cellar/ruby/3.0.0_1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from /opt/homebrew/lib/ruby/gems/3.0.0/gems/puma-5.2.1/lib/puma/server.rb:11:in `<top (required)>'
        from <internal:/opt/homebrew/Cellar/ruby/3.0.0_1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:/opt/homebrew/Cellar/ruby/3.0.0_1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from /opt/homebrew/lib/ruby/gems/3.0.0/gems/puma-5.2.1/lib/puma/runner.rb:3:in `<top (required)>'
        from <internal:/opt/homebrew/Cellar/ruby/3.0.0_1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:/opt/homebrew/Cellar/ruby/3.0.0_1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from /opt/homebrew/lib/ruby/gems/3.0.0/gems/puma-daemon-0.1.1/lib/puma/daemon.rb:3:in `<top (required)>'
        from <internal:/opt/homebrew/Cellar/ruby/3.0.0_1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:/opt/homebrew/Cellar/ruby/3.0.0_1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from /opt/homebrew/lib/ruby/gems/3.0.0/gems/puma-daemon-0.1.1/exe/pumad:4:in `<top (required)>'
        from /opt/homebrew/lib/ruby/gems/3.0.0/bin/pumad:23:in `load'
        from /opt/homebrew/lib/ruby/gems/3.0.0/bin/pumad:23:in `<main>'
brauliobo commented 3 years ago

same here

kigster commented 3 years ago

Could you retest with gem version 0.1.2? Thanks!

mpptx commented 3 years ago

Sorry to say that, nothing changed.

$ pumad
/opt/homebrew/lib/ruby/gems/3.0.0/gems/puma-5.2.1/lib/puma/binder.rb:12:in `<module:Puma>': uninitialized constant Puma::HAS_SSL (NameError)
        from /opt/homebrew/lib/ruby/gems/3.0.0/gems/puma-5.2.1/lib/puma/binder.rb:10:in `<top (required)>'
        from <internal:/opt/homebrew/Cellar/ruby/3.0.0_1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:/opt/homebrew/Cellar/ruby/3.0.0_1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from /opt/homebrew/lib/ruby/gems/3.0.0/gems/puma-5.2.1/lib/puma/server.rb:11:in `<top (required)>'
        from <internal:/opt/homebrew/Cellar/ruby/3.0.0_1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:/opt/homebrew/Cellar/ruby/3.0.0_1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from /opt/homebrew/lib/ruby/gems/3.0.0/gems/puma-5.2.1/lib/puma/runner.rb:3:in `<top (required)>'
        from <internal:/opt/homebrew/Cellar/ruby/3.0.0_1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:/opt/homebrew/Cellar/ruby/3.0.0_1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from /opt/homebrew/lib/ruby/gems/3.0.0/gems/puma-daemon-0.1.1/lib/puma/daemon.rb:3:in `<top (required)>'
        from <internal:/opt/homebrew/Cellar/ruby/3.0.0_1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:/opt/homebrew/Cellar/ruby/3.0.0_1/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from /opt/homebrew/lib/ruby/gems/3.0.0/gems/puma-daemon-0.1.1/exe/pumad:4:in `<top (required)>'
        from /opt/homebrew/lib/ruby/gems/3.0.0/bin/pumad:23:in `load'
        from /opt/homebrew/lib/ruby/gems/3.0.0/bin/pumad:23:in `<main>'
kigster commented 3 years ago

@mpptx You are still using version 0.1.1 of the gem, as can be seen from the third from the bottom line in your stack trace:

from /opt/homebrew/lib/ruby/gems/3.0.0/gems/puma-daemon-0.1.1/exe/pumad:4:in `<top (required)>'

If you are using a Gemfile, you should put gem "puma-daemon", "=0.1.2", require: false and runbundle update puma-daemon`.

If you are installing the gem using the gem command, you may need to re-install it:

gem uninstall puma-daemon --version 0.1.1
gem install puma-daemon --version 0.1.2 -N

Hope this helps. @kigster

mpptx commented 3 years ago

It helped! Thank you very much!