Skip to content

Broken compatibility with resolv-replace #44

Closed

Description

@Touchstone117

Hey,

I think I've found an issue introduced with the change in #10.

Changing from TCPSocket.open to Socket.tcp seems to break the functionality of resolv-replace.

Not sure if this was a by design change and if not if the right place for a fix is here or in resolv-replace itself.

Thanks

A test demonstrating the issue:

gem 'net-http', '0.2.0' # Fails
# gem 'net-http', '0.1.0' # Works
require 'net/http'
require 'resolv-replace'

fake_host = 'not.a.host'

hosts_file_name = 'hosts_file'

hosts_file = "#{Resolv.getaddress('google.com')} #{fake_host}"
File.write(hosts_file_name, hosts_file)

hosts_resolver = Resolv::Hosts.new(hosts_file_name)

dns_resolver = Resolv::DNS.new

Resolv::DefaultResolver.replace_resolvers([hosts_resolver, dns_resolver])

puts Net::HTTP.get(URI("http://#{fake_host}"))

Activity

  1. byroot commented on Apr 29, 2022

    @byroot
    Member

    That sounds more like resolv-replace that should be updated to also patch Scoket.tcp https://github.com/ruby/resolv-replace/blob/master/lib/resolv-replace.rb

  2. hsbt commented on Sep 8, 2026

    @hsbt
    Member

    The Socket.tcp change from #10 was reverted in 98caa38 and released in v0.3.0, so Net::HTTP#connect has used TCPSocket.open again ever since. Your script fails on v0.2.0 as you reported, and succeeds on v0.9.1 and on master. Removing resolv-replace makes it fail on master too, so the resolver patch is being exercised. If it still reproduces on the current stable release in your environment, please let me know.

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