Skip to content

Net::HTTP to a closed port raises SocketError where MRI raises Errno::ECONNREFUSED #772

Closed

Description

@tannevaled

Net::HTTP.get to a closed port raises the wrong exception class.

require "net/http"
begin
  Net::HTTP.get(URI("http://127.0.0.1:1/"))
rescue Exception => e
  puts "raised #{e.class}"
end
result
MRI 4.0.5 raised Errno::ECONNREFUSED
rbgo raised SocketError

Errno::ECONNREFUSED is what a program rescues to distinguish "nothing is listening" from a name-resolution or protocol failure, and retry logic is routinely written on exactly that distinction, so the substitution is not cosmetic: rescue Errno::ECONNREFUSED does not fire, and rescue SocketError catches both cases where MRI separates them.

Found alongside #771 while measuring the embedding surface for #768. Unlike #771 this one is a plain conformance divergence with no hang involved.

Worth checking the neighbouring cases in the same pass rather than only this one: ECONNRESET, EHOSTUNREACH, ETIMEDOUT and a genuine DNS failure (which should be SocketError), since whatever maps the Go error to a Ruby class here is likely to collapse those too. A census of the mapping would be better than a single-case fix.

🤖 Generated with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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