How to specify a read timeout for a Net::HTTP::Post.new request in Ruby 2

后端 未结 5 1080
生来不讨喜
生来不讨喜 2021-01-01 13:26

I have a post happening to a rails application from a ruby script. The script creates a variable request as

request = Net::HTTP::Post.new(url.path)
         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-01 14:04

    One thing to keep in mind is that if read_timeout is set to a small value such that a timeout does occur...Net::HTTP will "helpfully" retry the request. For a slow HTTP server, a timeout error may not be raised to the code calling Net::HTTP until 2x the read_timeout value.

    This certainly was not the behavior I expected.

    More info on this topic and how possible solutions differ for Ruby < 2.5 and >= 2.5 may be found here:

    https://stackoverflow.com/a/59186209/5299483

提交回复
热议问题