Reputation: 14746
I noticed that when a http request times out, Ruby (2.6.1) makes a second request. This causes problems with one of our endpoints, because a second worker is triggered which takes up resources.
You can see an example here: Go to https://beeceptor.com/console/timeout and run the following code
require "net/http"
http = Net::HTTP.new("timeout.free.beeceptor.com", 443)
http.read_timeout = 1
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.request(Net::HTTP::Get.new("/Time"))
You can see that there are 2 requests to /Time
, so I was wondering:
curl --max-time 1 https://timeout.free.beeceptor.com
Upvotes: 5
Views: 2829
Reputation: 23347
It's a feature of Net::HTTP
that it retries idempotent requests. You can limit number of retries by setting max_retries
(in your case to 0).
More on that issue on Ruby redmine
require "net/http"
http = Net::HTTP.new("timeout.free.beeceptor.com", 443)
http.read_timeout = 1
http.max_retries = 0 # <<<<<<<< the change
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.request(Net::HTTP::Get.new("/Time"))
Upvotes: 6