{"id":13411630,"url":"https://github.com/ankane/slowpoke","last_synced_at":"2025-11-17T14:08:07.218Z","repository":{"id":22228827,"uuid":"25561827","full_name":"ankane/slowpoke","owner":"ankane","description":"Rack::Timeout enhancements for Rails","archived":false,"fork":false,"pushed_at":"2025-10-22T05:15:26.000Z","size":86,"stargazers_count":395,"open_issues_count":0,"forks_count":15,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-11-11T02:14:41.303Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ankane.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-10-22T04:35:43.000Z","updated_at":"2025-11-04T09:50:59.000Z","dependencies_parsed_at":"2024-01-03T02:24:28.489Z","dependency_job_id":"4a9ce0c5-f7b7-427f-9069-3985fc38a3cb","html_url":"https://github.com/ankane/slowpoke","commit_stats":{"total_commits":135,"total_committers":7,"mean_commits":"19.285714285714285","dds":"0.051851851851851816","last_synced_commit":"a05ca907e884d7f882d500a2eb245c7911b4b3e2"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/ankane/slowpoke","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fslowpoke","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fslowpoke/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fslowpoke/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fslowpoke/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ankane","download_url":"https://codeload.github.com/ankane/slowpoke/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankane%2Fslowpoke/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284893613,"owners_count":27080540,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-17T02:00:06.431Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T20:01:15.171Z","updated_at":"2025-11-17T14:08:07.203Z","avatar_url":"https://github.com/ankane.png","language":"Ruby","readme":"# Slowpoke\n\n[Rack::Timeout](https://github.com/heroku/rack-timeout) enhancements for Rails\n\n- safer service timeouts\n- dynamic timeouts\n- custom error pages\n\n[![Build Status](https://github.com/ankane/slowpoke/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/slowpoke/actions)\n\n## Installation\n\nAdd this line to your application’s Gemfile:\n\n```ruby\ngem \"slowpoke\"\n```\n\nAnd run:\n\n```sh\nrails generate slowpoke:install\n```\n\nThis creates a `public/503.html` you can customize.\n\n## Development\n\nTo try out custom error pages in development, temporarily add to `config/environments/development.rb`:\n\n```ruby\nconfig.slowpoke.timeout = 1\nconfig.consider_all_requests_local = false\n```\n\nAnd add a `sleep` call to one of your actions:\n\n```ruby\nsleep(2)\n```\n\nThe custom error page should appear.\n\n## Production\n\nThe default timeout is 15 seconds. You can change this in `config/environments/production.rb` with:\n\n```ruby\nconfig.slowpoke.timeout = 5\n```\n\nFor dynamic timeouts, use:\n\n```ruby\nconfig.slowpoke.timeout = lambda do |env|\n  request = Rack::Request.new(env)\n  request.path.start_with?(\"/admin\") ? 15 : 5\nend\n```\n\nSubscribe to timeouts with:\n\n```ruby\nActiveSupport::Notifications.subscribe \"timeout.slowpoke\" do |name, start, finish, id, payload|\n  # report timeout\nend\n```\n\nTo learn more, see the [Rack::Timeout documentation](https://github.com/heroku/rack-timeout).\n\n## Safer Service Timeouts\n\nRack::Timeout can raise an exception at any point in the code, which can leave your app in an [unclean state](https://www.schneems.com/2017/02/21/the-oldest-bug-in-ruby-why-racktimeout-might-hose-your-server/). The safest way to recover from a request timeout is to spawn a new process. This is the default behavior for Slowpoke.\n\nFor threaded servers like Puma, this means killing all threads when any one of them times out. This can have a significant impact on performance.\n\nYou can customize this behavior with:\n\n```ruby\nSlowpoke.on_timeout do |env|\n  next if Rails.env.development? || Rails.env.test?\n\n  exception = env[\"action_dispatch.exception\"]\n  if exception \u0026\u0026 exception.backtrace.first.include?(\"/active_record/\")\n    Slowpoke.kill\n  end\nend\n```\n\nNote: To access `env[\"action_dispatch.exception\"]` in development, temporarily add to `config/environments/development.rb`:\n\n```ruby\nconfig.consider_all_requests_local = false\n```\n\n## Database Timeouts\n\nIt’s a good idea to set a [statement timeout](https://github.com/ankane/the-ultimate-guide-to-ruby-timeouts/#statement-timeouts-1) and a [connect timeout](https://github.com/ankane/the-ultimate-guide-to-ruby-timeouts/#activerecord). For Postgres, your `config/database.yml` should include something like:\n\n```yml\nproduction:\n  connect_timeout: 3 # sec\n  variables:\n    statement_timeout: 5s\n```\n\n## History\n\nView the [changelog](https://github.com/ankane/slowpoke/blob/master/CHANGELOG.md)\n\n## Contributing\n\nEveryone is encouraged to help improve this project. Here are a few ways you can help:\n\n- [Report bugs](https://github.com/ankane/slowpoke/issues)\n- Fix bugs and [submit pull requests](https://github.com/ankane/slowpoke/pulls)\n- Write, clarify, or fix documentation\n- Suggest or add new features\n\nTo get started with development:\n\n```sh\ngit clone https://github.com/ankane/slowpoke.git\ncd slowpoke\nbundle install\nbundle exec rake test\n```\n","funding_links":[],"categories":["Ruby","Production","生产"],"sub_categories":["Security","安全"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fslowpoke","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fankane%2Fslowpoke","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankane%2Fslowpoke/lists"}