-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix conflict with resolv-replace gem #989
Fix conflict with resolv-replace gem #989
Conversation
Closes petergoldstein#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.
I'm not sure this is possible to test without requiring And it looks like irb(Dalli::Socket::TCP):001> ::TCPSocket.private_instance_methods.include?(:original_resolv_initialize)
=> false
irb(Dalli::Socket::TCP):002> require 'resolv-replace'
/Users/yury.lebedev@carwow.de/development/personal/os/dalli/lib/dalli/socket.rb:2: warning: resolv-replace was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.4.0. Add resolv-replace to your Gemfile or gemspec.
=> true
irb(Dalli::Socket::TCP):003> ::TCPSocket.private_instance_methods.include?(:original_resolv_initialize)
=> true |
@y9v Given the very specific nature of this condition, can you please add a comment to the code explaining it? Thanks. |
3c5a71b
to
f8743b3
Compare
Thanks @y9v |
@petergoldstein thank you! |
@petergoldstein @y9v This is very similar to the problem with released versions of TruffleRuby. I had already been working on a PR to fix that when this one landed. If I add yet another check for TruffleRuby here the code is going to start looking a little long in the tooth. Assuming you want to continue using HAS_CONNECT_TIMEOUT = RUBY_VERSION >= '3.0' && TCPSocket.instance_method(:initialize).parameters.include?(%i[key connect_timeout])
if HAS_CONNECT_TIMEOUT
# use TCPSocket with :connect_timeout
else
# use Timeout.timeout around TCPSocket
end In my PR I was trying to limit that check to TruffleRuby so CRuby doesn't have to pay the cost of the method inspection, but it looks like we need to do something on CRuby anyway due to resolv-replace. I think the feature inspection approach addresses the resolv-replace case as well as currently released versions of TruffleRuby. |
@nirvdrum I personally like the idea, but in this particular case a constant wouldn't work, since we don't have a guarantee that |
(I'm following this since it affects TruffleRuby compatibility)
I would like to suggest to either simply always use Or alternatively then try to pass the |
I found the original PR adding Also there is another problem in that PR: https://github.com/petergoldstein/dalli/pull/977/files#r1482024393. |
One last comment for tonight, the |
@petergoldstein Do you have thoughts on this discussion? I'm willing to do the work to clean things up but wanted to make sure I was solving it in an acceptable way. |
@nirvdrum At this point my inclination is to revert the changes wholesale. I merged them in the first place because they were a better match for the actual (C)Ruby socket API since 3.0, as I read the intention of that API. But the level of complexity necessary to deal with incompatibilities - resolv-replace, socksify, TruffleRuby, indicates that it simply may not be worth it. And I am concerned about a potential performance hit. |
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.