我注意到当http请求超时时,Ruby (2.6.1)会发出第二个请求。这会导致我们的一个端点出现问题,因为第二个工作人员会被触发,占用资源。
您可以在这里看到一个示例:转到https://beeceptor.com/console/timeout并运行以下代码
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"))您可以看到对/Time有两个请求,所以我想知道:
curl --max-time 1 https://timeout.free.beeceptor.com发布于 2019-07-03 08:17:02
它是Net::HTTP的一个特性,它重试幂等请求。您可以通过设置max_retries来限制重试次数(在您的情况下为0)。
关于这个问题的更多关于红宝石的信息
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"))https://stackoverflow.com/questions/56864275
复制相似问题