Rails 7.1.2 upgrade, Rack::Handler deprecation warning

We’re on 7.0.8, and I’m trying to upgrade to 7.1.2. When I run rspec, I get a bunch of these warnings:

Rack::Handler is deprecated and replaced by Rackup::Handler

What am I doing wrong? How can I make this go away?

We’re on puma (6.4.0), rack (3.0.8), rackup (2.1.0), railties (7.1.2)


1 Like

I go this same error. The error is emitted by the rackup gem if using the older Rack::Server class instead of the renamed Rackup::Server class. This was part of Rack doing a bit of re-org and splitting off the rackup gem. See the upgrade guide for more info.

For me the source was an extension to the Rack::Server by rails_semantic_logger. For you it might be some other gem. How I found this was:

  1. Run bundle info rackup to find where rackup is installed
  2. At that location edit the lib/rack/server.rb file by putting warn caller prior to the warn line.
  3. Run the application. Where you previously just got the warning you now get a whole backtrace making it easy to see who is referencing Rack::Server instead of Rackup::Server.
  4. Follow up with the offending gem with a PR to help us all. :slight_smile: (still on my todo list for rails_semantic_logger)
  5. Don’t forget to remove puts caller from your installation of the rackup gem.
1 Like

In my case this was caused by capybara/registrations/server.rb. It does not appear to be a major issue at the moment since Rackup redirects the request to Rackup::Handler. I wonder how long that will last?

1 Like

If you would like to avoid the deprecation warnings while you await the next Capybara release (which should fix the issue), the following workaround did the trick:

if Rails.env.test?
  require 'rackup'

  module Rack
    Handler = ::Rackup::Handler

Same it was capybara for me:

F../Users/dorianmariefr/.asdf/installs/ruby/3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/Users/dorianmariefr/.asdf/installs/ruby/3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/Users/dorianmariefr/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/bootsnap-1.17.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/dorianmariefr/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
/Users/dorianmariefr/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/skylight-6.0.3/lib/skylight/probes.rb:166:in `require'
/Users/dorianmariefr/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/capybara-3.39.2/lib/capybara/registrations/servers.rb:31:in `block in <main>'
/Users/dorianmariefr/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/capybara-3.39.2/lib/capybara/config.rb:64:in `block in server='
/Users/dorianmariefr/.asdf/installs/ruby/3.3.0/lib/ruby/gems/3.3.0/gems/capybara-3.39.2/lib/capybara/server.rb:77:in `block in boot'
Rack::Handler is deprecated and replaced by Rackup::Handler

doing unless Rack::Handler::Puma.respond_to?(:config) in lib/capybara/registrations/servers.rb:31

Also I prefer bundle show rackup (it shows just the path)

And it was lib/rack/handler.rb

It’s been fixed in capybara capybara/lib/capybara/registrations/servers.rb at master · teamcapybara/capybara · GitHub

Fix deprecation warning when booting puma using rack 3 by mattbrictson · Pull Request #2706 · teamcapybara/capybara · GitHub not released

1 Like