Skip to content

Commit

Permalink
Fix conflict with resolv-replace gem (#989)
Browse files Browse the repository at this point in the history
* Fix conflict with resolv-replace gem

Closes #987

In version 3.2.7 socket_timeout option was introduced for TCPSocket.

This works unless `resolv-replace` gem is loaded (which was added to
ruby standard library since version 3.0.0).

This commit adds another check besides the ruby version check to avoid
breaking dalli for applications that have `resolv-replace` gem required.

* Fix rubocop warning

* Comment additional check in TCP.open method definition
  • Loading branch information
y9v committed Feb 4, 2024
1 parent c5aea22 commit bec0440
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/dalli/socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bec0440

Please sign in to comment.