Created
January 30, 2023 21:06
-
-
Save ericboehs/4dcca8f5d73872d903811af41e729568 to your computer and use it in GitHub Desktop.
Ruby Read Timeout vs Global
This file contains hidden or 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 'uri' | |
require 'net/http' | |
url = URI.parse 'http://localhost:9292/' | |
request = Net::HTTP::Get.new url.path | |
response = Net::HTTP.start(url.host, url.port) do |http| | |
http.read_timeout = 2 | |
http.request request | |
end | |
puts 'Timeout was not reached!' |
This file contains hidden or 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 'rack/handler/puma' | |
class App | |
def call(request) | |
delay = 1 # second | |
body = Enumerator.new do |enum| | |
5.times do |i| | |
puts "Sleeping #{delay}" | |
sleep delay | |
enum << "#{i}\n" | |
end | |
end | |
[200, { 'Content-Type' => 'application/json'}, body] | |
end | |
end | |
Rack::Handler::Puma.run App.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read timeouts aren't global timeouts.