Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

slowpoke

> 编程语言
Open source

Rack::Timeout enhancements for Rails

395 stars0 likes1 views
WebsiteGitHub

About

Rack::Timeout enhancements for Rails

Slowpoke

Rack::Timeout enhancements for Rails

  • safer service timeouts
  • dynamic timeouts
  • custom error pages

Installation

Add this line to your application’s Gemfile:

ruby
gem "slowpoke"

And run:

bash
rails generate slowpoke:install

This creates a public/503.html you can customize.

Development

To try out custom error pages in development, temporarily add to config/environments/development.rb:

ruby
config.slowpoke.timeout = 1
config.consider_all_requests_local = false

And add a sleep call to one of your actions:

ruby
sleep(2)

The custom error page should appear.

Production

The default timeout is 15 seconds. You can change this in config/environments/production.rb with:

ruby
config.slowpoke.timeout = 5

For dynamic timeouts, use:

ruby
config.slowpoke.timeout = lambda do |env|
  request = Rack::Request.new(env)
  request.path.start_with?("/admin") ? 15 : 5
end

Subscribe to timeouts with:

ruby
ActiveSupport::Notifications.subscribe "timeout.slowpoke" do |name, start, finish, id, payload|
  # report timeout
end

To learn more, see the Rack::Timeout documentation.

Safer Service Timeouts

Rack::Timeout can raise an exception at any point in the code, which can leave your app in an unclean state. The safest way to recover from a request timeout is to spawn a new process. This is the default behavior for Slowpoke.

For threaded servers like Puma, this means killing all threads when any one of them times out. This can have a significant impact on performance.

You can customize this behavior with:

ruby
Slowpoke.on_timeout do |env|
  next if Rails.env.development? || Rails.env.test?

  exception = env["action_dispatch.exception"]
  if exception && exception.backtrace.first.include?("/active_record/")
    Slowpoke.kill
  end
end

Note: To access env["action_dispatch.exception"] in development, temporarily add to config/environments/development.rb:

ruby
config.consider_all_requests_local = false

Database Timeouts

It’s a good idea to set a statement timeout and a connect timeout. For Postgres, your config/database.yml should include something like:

yaml
production:
  connect_timeout: 3 # sec
  variables:
    statement_timeout: 5s

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

  • Report bugs
  • Fix bugs and submit pull requests
  • Write, clarify, or fix documentation
  • Suggest or add new features

To get started with development:

bash
git clone https://github.com/ankane/slowpoke.git
cd slowpoke
bundle install
bundle exec rake test

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言