Async::HTTP::Endpoint#address fails with NoMethodError
Closed this issue · 3 comments
paddor commented
I'm integrating async-debug (it's awesome) and wanted to log the endpoint address. On Async::HTTP::Endpoint
I found #url
(what I'm probably conna use) and #address
.
Calling #address
causes a NoMethodError
because IO::Endpoint::HostEndpoint#address
doesn't exist.
Maybe that's supposed to be, maybe not. Just wanted to let you know.
paddor commented
Reproduction:
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'async'
gem 'async-debug'
end
Async do
endpoint = Async::HTTP::Endpoint.parse "http://localhost:3001"
Console.info "Serving live debugger at #{endpoint.url}"
Console.info "Serving live debugger at #{endpoint.address}" #=> NoMethodError
Async::Debug.serve endpoint: endpoint
end
Output:
$ ruby issue_167.rb
0.0s info: Serving live debugger at http://localhost:3001/ [ec=0x318] [pid=2640979] [2025-01-14 18:00:27 +0100]
0.0s warn: Async::Task [oid=0x320] [ec=0x318] [pid=2640979] [2025-01-14 18:00:27 +0100]
| Task may have ended with unhandled exception.
| NoMethodError: undefined method 'address' for an instance of IO::Endpoint::HostEndpoint (NoMethodError)
|
| endpoint.address
| ^^^^^^^^
| → /home/user/.gem/ruby/3.4.1/gems/async-http-0.86.0/lib/async/http/endpoint.rb:106 in 'Async::HTTP::Endpoint#address'
| issue_167.rb:13 in 'block in <main>'
| /home/user/.gem/ruby/3.4.1/gems/async-2.21.1/lib/async/task.rb:197 in 'block in Async::Task#run'
| /home/user/.gem/ruby/3.4.1/gems/async-2.21.1/lib/async/task.rb:435 in 'block in Async::Task#schedule'
ioquatix commented
A host endpoint is primarily based on a host name (string) and service name (string or integer). It does not have an address until we connect or bind, and the symbolic hostname is mapped to an actual socket address. Therefore, #address
does not exist.
Instead, you could use #to_s
, #inspect
or more specifically, #specification
.
paddor commented
Oh, that makes sense. Thank you.