Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Puma 5.0.3 deprecation warning in Ruby 2.7 - warning: deprecated Object#=~ is called on Proc #2455

Closed
ndbroadbent opened this issue Oct 26, 2020 · 6 comments

Comments

@ndbroadbent
Copy link

ndbroadbent commented Oct 26, 2020

I just pushed a new branch to update to puma 5.0.3, and I've configured my CI builds to crash on any warnings. I'm now seeing this warning in the logs:

vendor/bundle/ruby/2.7.0/gems/puma-5.0.3/lib/puma/server.rb:94: warning: deprecated Object#=~ is called on Proc; it always returns nil

(This is not happening with puma 5.0.2.)

Here is the line: https://github.com/puma/puma/blob/master/lib/puma/server.rb#L94

It looks like it changed 27 days ago in #2389 - this commit: bbce3d6

I found out that :environment is actually being set to a Proc here, in puma_default_options:

:environment => -> { ENV['RACK_ENV'] || ENV['RAILS_ENV'] || "development" },


It looks like this case is not being hit in the test suite since I couldn't find "Object#=~" in any of the log output here: https://github.com/puma/puma/runs/1308878188?check_suite_focus=true
It might be a good idea to add a new test case that exercises this code path, and then fail the tests if there are any warnings:

module Warning
  def warn(msg)
    raise msg
  end
end
@ndbroadbent ndbroadbent changed the title Puma 5.0.3 deprecation warning in Ruby 2.7 Puma 5.0.3 deprecation warning in Ruby 2.7 - warning: deprecated Object#=~ is called on Proc Oct 26, 2020
@nateberkopec
Copy link
Member

Thanks for the heads up. The suggested course of action sounds good.

@MSP-Greg
Copy link
Member

Thanks and interesting. We've also got the following, which is what I based the breaking code line on (I think):

puma/lib/puma/runner.rb

Lines 20 to 26 in d0f75b4

def development?
@options[:environment] == "development"
end
def test?
@options[:environment] == "test"
end

We'll add the warning change to the CI, as I've also seen some running locally...

@MSP-Greg
Copy link
Member

Something is odd.

I don't know if I've ever really gone thru the configuration code, but Puma::Configuration#clamp, which calls UserFileDefaultOptions#finalize_values, should 'convert' the lambda's/proc's into values. I must be missing something, or something's wrong with the code.

One problem with warnings is some are thrown by Ruby classes themselves in older Ruby versions. We still should be able to check them in the integration tests.

@MSP-Greg
Copy link
Member

@ndbroadbent

Using 5.0.3, I've started Puma via bin/puma and bin/rackup, and @options[:environment] is a String, or, no warnings. How are you starting Puma?

@ndbroadbent
Copy link
Author

ndbroadbent commented Oct 27, 2020

@MSP-Greg Really sorry for the missing details - I should have mentioned that puma does start correctly during development (and presumably production), but I run into this warning while running my RSpec test suite, which uses Capybara to start the puma server. I'm not familiar with how capybara is calling puma, but it could be skipping this UserFileDefaultOptions#finalize_values step. I wonder if this might be a bug in capybara in that case.

UPDATE: Yeah maybe the problem is actually in here, where capybara is setting up the puma server: https://github.com/teamcapybara/capybara/blob/d6a3e18f5c605236ae41ec90e872ae6a554c12fc/lib/capybara/registrations/servers.rb#L13-L44

@ndbroadbent
Copy link
Author

ndbroadbent commented Oct 27, 2020

Yep, I put a breakpoint in there, and conf.options[:environment] was a Proc. Calling conf.options.finalize_values fixed the issue so that conf.options[:environment] now returns "test". So I'll close this and open a PR in Capybara.

Here's the PR: teamcapybara/capybara#2413

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants