Created
February 5, 2014 11:15
-
-
Save elhu/8821429 to your computer and use it in GitHub Desktop.
Net::ReadTimeout weirdness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some weird stuff about NetHTTP, the timeout is twice what it should be. | |
To test things out: | |
$> gem install sinatra | |
$> ruby server.rb | |
$> ruby client.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
begin | |
start = Time.now | |
uri = URI 'http://localhost:4567' | |
req = Net::HTTP.new(uri.host, uri.port) | |
req.read_timeout = 5 | |
req.get(uri) | |
rescue Net::ReadTimeout | |
puts "Timed out after #{Time.now - start} seconds" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
get '/' do | |
puts 'Starting request' | |
sleep(25) | |
[200, 'slept 25s'] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment