From 9ba39a01e2d05513ec2351bf8c78e357709b3b8e Mon Sep 17 00:00:00 2001 From: Shouichi Kamiya Date: Mon, 24 Jun 2024 13:34:54 +0900 Subject: [PATCH 1/3] fix: require rack/handler for rack >= 3.1.x From rack >= 3.1.x, `Rack::Handler` is not auto-loaded anymore. Though we should migrate to `Rackup::Handler`, we can't in the short term. This is because of the support of rails <= 7.0 that doesn't depend on rackup. --- lib/good_job/probe_server/webrick_handler.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/good_job/probe_server/webrick_handler.rb b/lib/good_job/probe_server/webrick_handler.rb index 68e667bf5..4f5bc5bf8 100644 --- a/lib/good_job/probe_server/webrick_handler.rb +++ b/lib/good_job/probe_server/webrick_handler.rb @@ -7,6 +7,11 @@ def initialize(app, options = {}) @app = app @port = options[:port] @logger = options[:logger] + + # Workaround for rack >= 3.1.x as auto-loading of rack/handler was removed. + # We should move to rackup in the long run. + # See https://github.com/rack/rack/pull/1937. + require 'rack/handler' @handler = ::Rack::Handler.get('webrick') end From 50ca22c094b514257ed86647eaf296b828ee1e95 Mon Sep 17 00:00:00 2001 From: "Ben Sheldon [he/him]" Date: Mon, 24 Jun 2024 07:41:25 -0700 Subject: [PATCH 2/3] Try to load `rackup/handler` then fall back to `rack/handler` --- lib/good_job/probe_server/webrick_handler.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/good_job/probe_server/webrick_handler.rb b/lib/good_job/probe_server/webrick_handler.rb index 4f5bc5bf8..c73c2388a 100644 --- a/lib/good_job/probe_server/webrick_handler.rb +++ b/lib/good_job/probe_server/webrick_handler.rb @@ -11,8 +11,13 @@ def initialize(app, options = {}) # Workaround for rack >= 3.1.x as auto-loading of rack/handler was removed. # We should move to rackup in the long run. # See https://github.com/rack/rack/pull/1937. - require 'rack/handler' - @handler = ::Rack::Handler.get('webrick') + @handler = begin + require 'rackup/handler' + ::Rackup::Handler.get('webrick') + rescue LoadError + require "rack/handler" + ::Rack::Handler.get('webrick') + end end def stop From 5dda1f9a0e26dd69a8c98950e9cc8567bd1bb128 Mon Sep 17 00:00:00 2001 From: "Ben Sheldon [he/him]" Date: Mon, 24 Jun 2024 08:09:20 -0700 Subject: [PATCH 3/3] Fix tapioca definition and lint --- bin/tapioca | 1 + lib/good_job/probe_server/webrick_handler.rb | 12 ++--- sorbet/rbi/shims/rackup.rbi | 53 ++++++++++++++++++++ 3 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 sorbet/rbi/shims/rackup.rbi diff --git a/bin/tapioca b/bin/tapioca index a6ae7576e..c8cab51bf 100755 --- a/bin/tapioca +++ b/bin/tapioca @@ -24,4 +24,5 @@ end require "rubygems" require "bundler/setup" +ENV['BOOTSNAP_CACHE_DIR'] ||= File.expand_path("../demo/tmp/cache/bootsnap", __dir__) load Gem.bin_path("tapioca", "tapioca") diff --git a/lib/good_job/probe_server/webrick_handler.rb b/lib/good_job/probe_server/webrick_handler.rb index c73c2388a..65abfa5a1 100644 --- a/lib/good_job/probe_server/webrick_handler.rb +++ b/lib/good_job/probe_server/webrick_handler.rb @@ -12,12 +12,12 @@ def initialize(app, options = {}) # We should move to rackup in the long run. # See https://github.com/rack/rack/pull/1937. @handler = begin - require 'rackup/handler' - ::Rackup::Handler.get('webrick') - rescue LoadError - require "rack/handler" - ::Rack::Handler.get('webrick') - end + require 'rackup/handler' + ::Rackup::Handler.get('webrick') + rescue LoadError + require "rack/handler" + ::Rack::Handler.get('webrick') + end end def stop diff --git a/sorbet/rbi/shims/rackup.rbi b/sorbet/rbi/shims/rackup.rbi new file mode 100644 index 000000000..c16080077 --- /dev/null +++ b/sorbet/rbi/shims/rackup.rbi @@ -0,0 +1,53 @@ +# Manually exported via Tapioca because rackup is not compatible with Rack 2.0 +# which is used for development, but Rackup is is necessary as a fallback for +# Rack 3.0 compatibility. And Rackup 1.0 is bugged. +# +# https://github.com/rack/rackup/issues/13#issuecomment-2186788166 + +module Rackup; end +module Rackup::Handler + class << self + # source://rackup//lib/rackup/handler.rb#30 + def [](name); end + + # source://rackup//lib/rackup/handler.rb#84 + def default; end + + # source://rackup//lib/rackup/handler.rb#40 + def get(name); end + + # Select first available Rack handler given an `Array` of server names. + # Raises `LoadError` if no handler was found. + # + # > pick ['puma', 'webrick'] + # => Rackup::Handler::WEBrick + # + # @raise [LoadError] + # + # source://rackup//lib/rackup/handler.rb#69 + def pick(server_names); end + + # Register a named handler class. + # + # source://rackup//lib/rackup/handler.rb#18 + def register(name, klass); end + + # Transforms server-name constants to their canonical form as filenames, + # then tries to require them but silences the LoadError if not found + # + # Naming convention: + # + # Foo # => 'foo' + # FooBar # => 'foo_bar.rb' + # FooBAR # => 'foobar.rb' + # FOObar # => 'foobar.rb' + # FOOBAR # => 'foobar.rb' + # FooBarBaz # => 'foo_bar_baz.rb' + # + # source://rackup//lib/rackup/handler.rb#106 + def require_handler(prefix, const_name); end + end +end + +# source://rackup//lib/rackup/version.rb#7 +Rackup::VERSION = T.let(T.unsafe(nil), String)