diff --git a/lib/dalli/socket.rb b/lib/dalli/socket.rb index 48f3c3f2..efb94475 100644 --- a/lib/dalli/socket.rb +++ b/lib/dalli/socket.rb @@ -88,7 +88,14 @@ class TCP < TCPSocket # options - supports enhanced logging in the case of a timeout attr_accessor :options - if RUBY_VERSION >= '3.0' + # Check that TCPSocket#initialize was not overwritten by resolv-replace gem + # (part of ruby standard library since 3.0.0, should be removed in 3.4.0), + # as it does not handle keyword arguments correctly. + # To check this we are using the fact that resolv-replace + # aliases TCPSocket#initialize method to #original_resolv_initialize. + # https://github.com/ruby/resolv-replace/blob/v0.1.1/lib/resolv-replace.rb#L8 + if RUBY_VERSION >= '3.0' && + !::TCPSocket.private_instance_methods.include?(:original_resolv_initialize) def self.open(host, port, options = {}) sock = new(host, port, connect_timeout: options[:socket_timeout]) sock.options = { host: host, port: port }.merge(options)