Skip to content

Commit

Permalink
Merge pull request #128 from rage-rb/zero-timeouts
Browse files Browse the repository at this point in the history
Correctly handle `0` timeouts
  • Loading branch information
rsamoilov authored Feb 10, 2025
2 parents 7ec8bcd + a905dd0 commit 83a59f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/rage/fiber_scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ def initialize

def io_wait(io, events, timeout = nil)
f = Fiber.current
::Iodine::Scheduler.attach(io.fileno, events, timeout&.ceil || 0) { |err| f.resume(err) }
::Iodine::Scheduler.attach(io.fileno, events, timeout&.ceil) { |err| f.resume(err) }

err = Fiber.defer(io.fileno)
if err && err < 0
if err == false || (err && err < 0)
err
else
events
Expand Down
2 changes: 1 addition & 1 deletion rage.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Gem::Specification.new do |spec|

spec.add_dependency "thor", "~> 1.0"
spec.add_dependency "rack", "~> 2.0"
spec.add_dependency "rage-iodine", "~> 4.0"
spec.add_dependency "rage-iodine", "~> 4.1"
spec.add_dependency "zeitwerk", "~> 2.6"
spec.add_dependency "rack-test", "~> 2.1"
spec.add_dependency "rake", ">= 12.0"
Expand Down
17 changes: 17 additions & 0 deletions spec/fiber_scheduler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,23 @@
end
end

it "works correctly with persistent connections" do
uri = URI(TEST_HTTP_URL)

within_reactor do
connection = Net::HTTP.new(uri.hostname, uri.port)
connection.use_ssl = true
connection.verify_mode = OpenSSL::SSL::VERIFY_PEER
connection.start

responses = 3.times.map do
connection.get("/instant-http-get")
end

-> { expect(responses).to all(be_a(Net::HTTPOK)) }
end
end

context "with Postgres" do
let(:conn) { PG.connect(TEST_PG_URL) }

Expand Down

0 comments on commit 83a59f6

Please sign in to comment.