Skip to content

Instantly share code, notes, and snippets.

@elhu
Created February 5, 2014 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elhu/8821429 to your computer and use it in GitHub Desktop.
Save elhu/8821429 to your computer and use it in GitHub Desktop.
Net::ReadTimeout weirdness
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
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
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