Skip to content
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 socksify incompatibility #999

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sambostock
Copy link
Contributor

Similarly to resolv-replace, sockify monkey patches TCPSocket#initialize which causes an error if it is called with connect_timeout:.

Rather than check only for resolv-replace's specific method, we can check if if the method's parameters have changed.

This PR builds on #998 and adds the socksify gem to the list of gems to smoke test compatibility with.

Closes #996

⚠️ Before Merging

While `dalli` doesn't depend on `resolv-replace`, we want to ensure it
still works if it is required by the host application.

This regression test ensures we don't break compatibility, and adds a
framework allowing us to test compatibility with other gems in the
future.
Copy link
Contributor Author

@sambostock sambostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first commit is from #998, which I made as a separate PR because I think it makes sense to have the compatibility tests even if we decide to simply go back to exclusively relying on Timeout instead of connect_timeout:, as was discussed on #989 (comment).

@@ -97,15 +97,14 @@ def self.open(host, port, options = {})
end
end

TCPSOCKET_ORIGINAL_INITIALIZE_PARAMETERS = [[:rest].freeze].freeze
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is memoized so we don't create duplicate arrays every time.

if RUBY_VERSION >= '3.0' &&
!::TCPSocket.private_instance_methods.include?(:original_resolv_initialize)
::TCPSocket.instance_method(:initialize).parameters == TCPSOCKET_ORIGINAL_INITIALIZE_PARAMETERS
Copy link
Contributor Author

@sambostock sambostock Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just checks for the original parameters ([[:rest]]), but we could also use connect_timeout if we detect any of

  • parameters.include?([:key, :connect_timeout])
  • parameters.include?([:keyreq, :connect_timeout])
  • parameters.any? { |type, _name| type == :keyrest }

I kept it simple, as these would increase the runtime penalty, and I'm not aware of any gems that do monkey patch TCPSocket#initialize correctly, nor am I certain we must use connect_timeout: instead of Timeout in those cases. 🤷

@sambostock
Copy link
Contributor Author

sambostock commented Mar 8, 2024

I see

failed to listen on TCP port 21345: Address already in use
failed to listen on TCP port 33044: Address already in use
failed to listen on TCP port 33044: Address already in use

in the output of the only test runner that failed for the first commit, and similarly

failed to listen on TCP port 21345: Address already in use

in the output of the only test runner that failed for the second commit.

I feel like I've got flakey tests due to a bunch of the tests and helpers using hard coded ports instead of grabbing a free or simply random port.


I've opened #1000, which switches all test ports to be dynamically picked.

Similarly to `resolv-replace`, `sockify` monkey patches
`TCPSocket#initialize` which causes an error if it is called with
`connect_timeout:`.

Rather than check only for `resolv-replace`'s specific method, we can
check if if the method's parameters have changed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError raised in latest Socksify when initializing Dalli client with version 3.2.7+
1 participant