libev_scheduler icon indicating copy to clipboard operation
libev_scheduler copied to clipboard

No implicit conversion of Libev::Scheduler into Integer (TypeError) when used with Net::HTTP

Open EdwardDiehl opened this issue 2 years ago • 0 comments

# fibers.rb

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  # gem 'async-io', '~> 1.36', '>= 1.36.1'
  gem 'libev_scheduler', '~> 0.2'
end

# require 'async/scheduler'
require 'libev_scheduler'
require 'net/http'

# SCHEDULER = Async::Scheduler.new
SCHEDULER = Libev::Scheduler.new

Fiber.set_scheduler(SCHEDULER)

Fiber.schedule do
  response = Net::HTTP.get('example.com', '/index.html')
  puts response
end
$ ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]

$ ruby fibers.rb 
/home/username/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/net/protocol.rb:229:in `wait_readable': no implicit conversion of Libev::Scheduler into Integer (TypeError)

        (io = @io.to_io).wait_readable(@read_timeout) or raise Net::ReadTimeout.new(io)
                                       ^^^^^^^^^^^^^
	from /home/username/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/net/protocol.rb:229:in `rbuf_fill'
	from /home/username/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/net/protocol.rb:199:in `readuntil'
	from /home/username/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/net/protocol.rb:209:in `readline'
	from /home/username/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/net/http/response.rb:158:in `read_status_line'
	from /home/username/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/net/http/response.rb:147:in `read_new'
	from /home/username/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/net/http.rb:1862:in `block in transport_request'
	from /home/username/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/net/http.rb:1853:in `catch'
	from /home/username/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/net/http.rb:1853:in `transport_request'
	from /home/username/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/net/http.rb:1826:in `request'
	from /home/username/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/net/http.rb:1727:in `request_get'
	from /home/username/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/net/http.rb:475:in `block in get_response'
	from /home/username/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/net/http.rb:1238:in `start'
	from /home/username/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/net/http.rb:474:in `get_response'
	from /home/username/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/net/http.rb:461:in `get'
	from fibers2.rb:18:in `block in <main>'

Works fine with other scheduler, for example with async-io Async::Scheduler.

EdwardDiehl avatar Nov 01 '23 20:11 EdwardDiehl