rubygems / gemstash

A RubyGems.org cache and private gem server
MIT License
753 stars 121 forks source link

Undefined constant Puma::HAS_NATIVE_IO_WAIT when running `gemstash authorize` #361

Closed ktreis closed 1 year ago

ktreis commented 1 year ago

My Gemstash 2.3.1 server works fine with Puma 6.3.1 under Ruby 2.7, but gemstash authorize fails with the following error:

    22: from /usr/local/bundle/bin/gemstash:25:in `<main>'
    21: from /usr/local/bundle/bin/gemstash:25:in `load'
    20: from /usr/local/bundle/gems/gemstash-2.3.1/exe/gemstash:6:in `<top (required)>'
    19: from /usr/local/bundle/gems/gemstash-2.3.1/lib/gemstash/cli.rb:34:in `start'
    18: from /usr/local/bundle/gems/thor-1.2.2/lib/thor/base.rb:485:in `start'
    17: from /usr/local/bundle/gems/thor-1.2.2/lib/thor.rb:392:in `dispatch'
    16: from /usr/local/bundle/gems/thor-1.2.2/lib/thor/invocation.rb:127:in `invoke_command'
    15: from /usr/local/bundle/gems/thor-1.2.2/lib/thor/command.rb:27:in `run'
    14: from /usr/local/bundle/gems/gemstash-2.3.1/lib/gemstash/cli.rb:59:in `authorize'
    13: from /usr/local/bundle/gems/gemstash-2.3.1/lib/gemstash/cli/authorize.rb:12:in `run'
    12: from /usr/local/bundle/gems/gemstash-2.3.1/lib/gemstash/cli/base.rb:22:in `prepare'
    11: from /usr/local/bundle/gems/gemstash-2.3.1/lib/gemstash/cli/base.rb:41:in `check_gemstash_version'
    10: from /usr/local/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:86:in `require'
     9: from /usr/local/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:86:in `require'
     8: from /usr/local/bundle/gems/gemstash-2.3.1/lib/gemstash/storage.rb:9:in `<top (required)>'
     7: from /usr/local/bundle/gems/gemstash-2.3.1/lib/gemstash/storage.rb:93:in `<module:Gemstash>'
     6: from /usr/local/bundle/gems/gemstash-2.3.1/lib/gemstash/storage.rb:95:in `<class:Resource>'
     5: from /usr/local/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:86:in `require'
     4: from /usr/local/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:86:in `require'
     3: from /usr/local/bundle/gems/gemstash-2.3.1/lib/gemstash/logging.rb:6:in `<top (required)>'
     2: from /usr/local/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:86:in `require'
     1: from /usr/local/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:86:in `require'
/usr/local/bundle/gems/puma-6.3.1/lib/puma/log_writer.rb:6:in `<top (required)>': uninitialized constant Puma::HAS_NATIVE_IO_WAIT (NameError)

I thin the problem is in the way Gemstash detects whether it's on Puma 6, via this code:

https://github.com/rubygems/gemstash/blob/6800bdde1458fae1a3fddbdd4dd613fa180e5700/lib/gemstash/logging.rb#L6

Looking at the Puma sources, it doesn't appear that this file is intended to be loaded independently; it expects the HAS_NATIVE_IO_WAIT constant to be defined before this code is loaded:

https://github.com/puma/puma/blob/04b8b09ad20ace1a3a5cfe06375dc24818697d19/lib/puma/log_writer.rb#L6

... which would mean that we'd at least need to require puma/detect before attempting to loading puma/log_writer. Or perhaps there's a better way to detect Puma 6?

ktreis commented 1 year ago

Confirmed, loading puma/detect before puma/log_writer appears to fix this issue.

olleolleolle commented 1 year ago

@ktreis When you have the time, v2.3.2 should have that change in it.