https://github.com/sharpstone/rack-timeout 使う
Gemfile
group :development do
gem 'rack-timeout'
end
.env
# 1 second
RACK_TIMEOUT_SERVICE_TIMEOUT=1
config/environments/development.rb
Rails.application.configure do
config.action_dispatch.rescue_responses["Rack::Timeout::RequestTimeoutException"] = :gateway_timeout
...
結果 =>
Processing by SessionsController#new as HTML
Rendering layout layouts/application.html.slim
Rendering sessions/new.html.slim within layouts/application
Rendered sessions/new.html.slim within layouts/application (Duration: 103.4ms | Allocations: 45561)
source=rack-timeout id=924ea792-3653-4aa8-a305-7eaa051e685a timeout=1000ms service=1068ms state=active
source=rack-timeout id=924ea792-3653-4aa8-a305-7eaa051e685a timeout=1000ms service=1245ms state=timed_out
Rendered layout layouts/application.html.slim (Duration: 1243.9ms | Allocations: 185715)
Completed 504 Gateway Timeout in 1349ms (ActiveRecord: 0.0ms | Allocations: 225358)