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

Ruby 3.2 will have native IO#wait_* methods, don't require io/wait #2903

Merged
merged 2 commits into from
Aug 27, 2022

Conversation

MSP-Greg
Copy link
Member

@MSP-Greg MSP-Greg commented Jul 2, 2022

Description

In Ruby 3.1 and earlier versions, IO#wait_* methods were contained in the standard library gem io/wait. Ruby 3.2 has moved the methods to the main IO code. See 'Move wait* methods to io.c' ruby/ruby#6036.

So, io/wait does not need to be required for Ruby 3.2 and later. Adjust code to only require it when needed.

Your checklist for this pull request

  • I have reviewed the guidelines for contributing to this repository.
  • I have added (or updated) appropriate tests if this PR fixes a bug or adds a feature.
  • My pull request is 100 lines added/removed or less so that it can be easily reviewed.
  • If this PR doesn't need tests (docs change), I added [ci skip] to the title of the PR.
  • If this closes any issues, I have added "Closes #issue" to the PR description or my commit messages.
  • I have updated the documentation accordingly.
  • All new and existing tests passed, including Rubocop.

@MSP-Greg MSP-Greg merged commit cf973d5 into puma:master Aug 27, 2022
@MSP-Greg MSP-Greg deleted the 00-io-wait-native branch August 27, 2022 16:12
JuanitoFatas pushed a commit to JuanitoFatas/puma that referenced this pull request Sep 9, 2022
…uma#2903)

* detect.rb - add Puma::HAS_NATIVE_IO_WAIT

* Change io/wait requires
@silva96
Copy link

silva96 commented Nov 8, 2022

I'm running ruby 3.1 and ::IO.public_instance_methods(false).include? :wait_readable returns true. This causes the io/wait library not being loaded I suppose. Then my puma wont start:

 Early termination of worker
[1979180] + Gemfile in context: /home/ubuntu/www/releases/20221108181543/Gemfile
[1979176] ! Unable to start worker
[1979176] /home/ubuntu/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/bundler-2.3.12/lib/bundler/runtime.rb:309:in `check_for_activated_spec!'

I upgraded from rails (7.0.2.4) to rails (7.0.4)

@MSP-Greg
Copy link
Member Author

MSP-Greg commented Nov 8, 2022

I'm running ruby 3.1 and ::IO.public_instance_methods(false).include? :wait_readable returns true

Something is loading io/wait, if I run that via the below, it returns false.

ruby -e "puts ::IO.public_instance_methods(false).include? :wait_readable"

Any changes re Ruby default gems in your Gemfile.lock when you upgraded?

@silva96
Copy link

silva96 commented Nov 8, 2022

This is the gist of the upgrade:

https://gist.github.com/silva96/f69a42f9ef3510e7761a8331a13edd3e

@MSP-Greg
Copy link
Member Author

MSP-Greg commented Nov 8, 2022

Can you try a patch? Might be something particular with your setup. There are three files that have the conditional:

unless Puma::HAS_NATIVE_IO_WAIT

change that to:

unless ::IO.public_instance_methods(false).include?(:wait_readable)

@MSP-Greg
Copy link
Member Author

MSP-Greg commented Nov 9, 2022

Finally looked at Bundler code to see what was happening...

This causes the io/wait library not being loaded I suppose

Nothing in the log you've shown indicates that. I suspect you need to add io-wait to your Gemfile, as the error logged probably implies that Bundler can't locate it.

EDIT: Not sure what is going on, as I just checked locally. io-wait is not in my Gemfile.lock. Puma loads correctly. Using Ruby 3.1.2 with Bundler 2.3.12 installed, as listed above.

@silva96
Copy link

silva96 commented Nov 9, 2022

Yes is not in mine either, it never was. But I read somewhere that rails removed it from their dependencies in the latests versions. I came from this issue: #2843

@MSP-Greg
Copy link
Member Author

MSP-Greg commented Nov 9, 2022

I assume you're having the problem with restarts? Regardless, can you patch Puma, or work from a GitHub branch, etc?

The Puma code that's logging what you listed is:

rescue Exception => e
log "! Unable to start worker"
log e
log e.backtrace.join("\n ")
exit 1
end

So, the line log e is showing pretty much nothing. Not sure if we can get more info, but maybe e.class and/or e.message may have more info. Not.Sure.

EDIT: Given what's raising the error, maybe the following:

rescue Exception => e
  log "! Unable to start worker"
  log "class: #{e.class}"
  log "  msg: #{e.message}"
  if e.respond_to? :requirement
    log "gem name: #{e.name}"
    log "     req: #{e.requirement}"
  end
  log e.backtrace.join("\n    ")
  exit 1
end

@silva96
Copy link

silva96 commented Nov 9, 2022

Thanks I'll give it a try maybe on friday and let you know the output.

@MSP-Greg
Copy link
Member Author

MSP-Greg commented Nov 9, 2022

Thanks.

FYI, the above isn't fixing anything, but it's an attempt to get more info about what went wrong.

As in #2843, it's difficult to repo locally, and since you've got the problem, the above patch should (hopefully) show enough info to identify the problem...

@silva96
Copy link

silva96 commented Nov 11, 2022

Just if it helps, this is my puma.rb config in production:

#!/usr/bin/env puma

directory '/home/ubuntu/www/current'
rackup "/home/ubuntu/www/current/config.ru"
environment 'production'

tag ''

pidfile "/home/ubuntu/www/shared/tmp/pids/puma.pid"
state_path "/home/ubuntu/www/shared/tmp/pids/puma.state"
stdout_redirect '/home/ubuntu/www/shared/log/puma_access.log', '/home/ubuntu/www/shared/log/puma_error.log', true

threads 0,16

bind 'unix:///home/ubuntu/www/shared/tmp/sockets/puma.sock'

workers 2

prune_bundler

on_restart do
  puts 'Refreshing Gemfile'
  ENV["BUNDLE_GEMFILE"] = ""
end

@silva96
Copy link

silva96 commented Nov 11, 2022

Ok I found the problem,

Context: I'm deploying using capistrano, and after deploy I restart puma using systemd

In my puma.service

# I changed this
ExecStart=/home/ubuntu/.asdf/shims/puma -C /home/ubuntu/www/shared/puma.rb
# to this
ExecStart=/usr/bin/bash -lc '/home/ubuntu/.asdf/shims/bundle exec puma -C /home/ubuntu/www/shared/puma.rb'

The thing is after deploying, asdf puma shim was not being updating from 5.x to 6 so the Gemfile version differed from the puma that was running.

Using bundle exec would run the puma version recently installed.

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

Successfully merging this pull request may close these issues.

2 participants