Global timeouts for Ruby's Net::HTTP
.
Net::HTTP
by default has a connect timeout of 60 seconds and a request timeout of 60 seconds, a 2 minutes worst-case scenario timeout, with auto-retry.
These defaults are kinda dangerous in a micro-services environment, where requests should happen fast or just timeout, to avoid server processes locking.
This gem lets you globally restrict timeouts of Net::HTTP
calls, so that all gems and libraries that use Net::HTTP
will timeout fast.
- Add it to your Gemfile:
gem 'http-cage'
# Initialize the cage in your app initializer.
HTTPCage.timeout(connection: 3, request: 5)
# Increase global timeouts in a delayed job, for example.
HTTPCage.timeout(connection: 10, request: 30)
bundle exec rake test:all
- Forking server, slow request: example.rb
- Without http-cage: without_cage.rb
- With http-cage: with_cage.rb
- We use GitHub issues to discuss everything: features, bugs, docs.
- Before sending a pull request always open an issue.
- Designer: Francesca Segantini
- Director: Justin Dorfman