Skip to content

Cannot use Async::HTTP from inside a Ractor #218

@cyberarm

Description

@cyberarm
require "async/http/internet/instance"

r = Ractor.new do
  Sync do
    Async::HTTP::Internet.get("https://httpbin.org/get") do |response|
      puts response.read
    end
  end
end

r.join # make process wait for ractor to run
> ruby _async_http_ractor.rb
_async_http_ractor.rb:2: warning: Ractor API is experimental and may change in future versions of Ruby.
#<Thread:0x00007f005daaaf00 run> terminated with exception (report_on_exception is true):
_async_http_ractor.rb:5:in 'block (2 levels) in <main>': defined with an un-shareable Proc in a different Ractor (RuntimeError)
	from /home/cyberarm/.rbenv/versions/4.0.0/lib/ruby/gems/4.0.0/gems/async-2.36.0/lib/async/task.rb:234:in 'block in Async::Task#run'
	from /home/cyberarm/.rbenv/versions/4.0.0/lib/ruby/gems/4.0.0/gems/async-2.36.0/lib/async/task.rb:512:in 'block in Async::Task#schedule'
_async_http_ractor.rb:10:in 'Ractor#join': thrown by remote Ractor. (Ractor::RemoteError)
	from _async_http_ractor.rb:10:in '<main>'
_async_http_ractor.rb:5:in 'block (2 levels) in <main>': defined with an un-shareable Proc in a different Ractor (RuntimeError)
	from /home/cyberarm/.rbenv/versions/4.0.0/lib/ruby/gems/4.0.0/gems/async-2.36.0/lib/async/task.rb:234:in 'block in Async::Task#run'
	from /home/cyberarm/.rbenv/versions/4.0.0/lib/ruby/gems/4.0.0/gems/async-2.36.0/lib/async/task.rb:512:in 'block in Async::Task#schedule'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions