-
Notifications
You must be signed in to change notification settings - Fork 996
Adapter support for Net::HTTP::Persistent v3.0.0 #619
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks for trying to solve this!
Gemfile
Outdated
@@ -13,7 +13,11 @@ group :test do | |||
gem 'httpclient', '>= 2.2' | |||
gem 'mime-types', '~> 1.25', :platforms => [:jruby, :ruby_18] | |||
gem 'minitest', '>= 5.0.5' | |||
gem 'net-http-persistent', '~> 2.9.4' | |||
if RUBY_VERSION >= '2.1' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't use conditionals like these in a Gemfile. However, you can use the :platform
to scope only to certain Rubies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http://bundler.io/v1.13/man/gemfile.5.html#PLATFORMS seems not to support this use-case.
http://bundler.io/v1.13/man/gemfile.5.html#INSTALL_IF is perhaps a candidate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[!] There was an error parsing `Gemfile`: You cannot specify the same gem twice with different version requirements.
You specified: net-http-persistent (>= 0) and net-http-persistent (~> 2.9.4). Bundler cannot continue.
# from /Users/olle/opensource/faraday/Gemfile:20
# -------------------------------------------
# install_if -> { RUBY_VERSION < '2.1' } do
> gem 'net-http-persistent', '~> 2.9.4'
# end
# -------------------------------------------
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mislav This looks like the only working solution and is what it was done already in the past for other gems at the bottom of the Gemfile. Given the Gemfile is only used for tests, I think that is acceptable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iMacTia Would you want a squash-and-rebase? Any other changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I personally think that even though it's not the most elegant solution, this is the only one we can use in this specific case. So I'm saying that for me it's ok as it is.
@@ -17,8 +17,11 @@ def with_net_http_connection(env) | |||
define_method(:password) { proxy[:password] } | |||
end if proxy[:user] | |||
end | |||
|
|||
yield Net::HTTP::Persistent.new 'Faraday', proxy_uri | |||
if Net::HTTP::Persistent::VERSION >= '3' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of checking a version string like this, could we simply check the arity of the constructor?
Net::HTTP::Persistent.method(:new).arity
We could detect how many arguments does the constructor expect this way, and switch between two different invocation styles without being dependent on the version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our problem here is that they both (3.x and 2.x) return -1
for that arity - they both default on each of the given arguments.
Inspired by this comment, I changed the test invocation to avoid testing for the version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙇🏻
I switched this to open the possibility of adding arbitrary configuration keyword argument to the constructor. Keeping the few positional arguments seemed silly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will break if there is ever a net-http-persistent 10 release, but otherwise is fine.
@@ -10,8 +10,10 @@ def setup | |||
if defined?(Net::HTTP::Persistent) | |||
# work around problems with mixed SSL certificates | |||
# https://github.com/drbrain/net-http-persistent/issues/45 | |||
http = Net::HTTP::Persistent.new('Faraday') | |||
http.ssl_cleanup(4) | |||
if Net::HTTP::Persistent::VERSION < '3' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto my comment about version string checking.
if Net::HTTP::Persistent::instance_methods.include?(:ssl_cleanup) | ||
http = Net::HTTP::Persistent.new('Faraday') | ||
http.ssl_cleanup(4) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this fixed in version 3.0 or simply the method was removed/renamed?
The issue appears to be still open and we're now skipping the ssl_cleanup...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iMacTia: There's no longer any "cleanup" method in 3.0.0.
https://github.com/drbrain/net-http-persistent/commits/master
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Investigating.)
Is this the current cleanup? drbrain/net-http-persistent@dad5d68
I begin to think that this is the current way of "cleaning up" after finishing a connection.
Here's the ssl_cleanup
implementation's comment (in v2.9.4):
Finishes all connections on the given +thread+ that were created before
the given +generation+ in the threads +generation_key+ list.
See #shutdown for a bunch of scary warning about misusing this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, looks like you have to use this reuse_ssl_sessions
. Did you spot also what the default value is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This 2011 note from History.txt said:
For HTTPS connections, SSL sessions are now reused avoiding the extra
round trips and computations of extra SSL handshakes. If you have
problems with SSL session reuse it can be disabled by
Net::HTTP::Persistent#reuse_ssl_sessions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answer: By default, SSL connections are reused: https://github.com/drbrain/net-http-persistent/blob/master/lib/net/http/persistent.rb#L409 Set to false
to not do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok so in order for tests to work properly, we need to set this to false at the beginning.
I'm wondering if this option exists on v2.9 as well given it was there in 2011 😮
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment immediately above this references issues with SSL client certificates, I think the correct thing to do is to call reconnect_ssl
to address that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try adding a case for when that method is available and then use it.
But it is a test setup, and I'll have to check if the 4
in this cleanup isn't an exact ssl generation number to reset to (synthetically keeping it there to be able to count and compare ssl generation changing when different operations are tested).
Thanks for the hints, all!
@drbrain Sorry I took forever, but I made a conditional |
@iMacTia The last change to the Gemfile is one I was really aching to get in: using the See Bundler's docs on Gemfile for (spare) details: http://bundler.io/v1.13/man/gemfile.5.html#RUBY I hope it can be used as it is; support for it arrived in Bundler 1.2 - otherwise we need to have a |
Maybe I'm missing something, but looking at this I don't find a reason to specify something like |
@@ -10,8 +10,13 @@ def setup | |||
if defined?(Net::HTTP::Persistent) | |||
# work around problems with mixed SSL certificates | |||
# https://github.com/drbrain/net-http-persistent/issues/45 | |||
http = Net::HTTP::Persistent.new('Faraday') | |||
http.ssl_cleanup(4) | |||
if Net::HTTP::Persistent::instance_methods.include?(:ssl_cleanup) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#reconnect_ssl exists back to net-http-persistent v2.4.1, so you probably don't need this if
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Well, I needed the if in order to new with the 2 arities of constructor.)
Oh, the very thing is that we're not a deployed application where dependencies are to be locked down to 1 and only 1 gem selection, but a library which needs 1 selection per Ruby version we support. Warning: This is more of a current measure, Bundler's future has better support for knowing this on its own. So by leveraging Bundler's "Ruby version hinting", we can try to minimize Bundler outsources the decision about sub-dependencies' version needs to the gemspecs involved, by taking the (You know, I'll try improving the Bundler website with an FAQ item about just this.) |
any update on this? |
There are some important changes to the Gemfile, so I would like @mislav to review this PR as well before merging it in. |
Is the issue about how to support both 2.x and 3.x of |
@aaronmcadam Yes! |
Hey @olleolleolle I've not used it myself, but I've seen https://github.com/thoughtbot/appraisal being used for supporting multiple gem versions. |
@aaronmcadam I will extend the Description of this PR, in order to make it clear what the changes are and why they're needed. |
Hi @olleolleolle ! Any idea when this will be available ? Thanks 👍 |
@iancward To meet earlier requested change: Formulate a parameters-based version picking, instead of using the VERSION constant. |
If it is helpful, I've been using a version of the patch provided by @olleolleolle for a few projects (by way of making a new adapter available) and it has worked superbly. |
Tests are passing and changes from @mislav have been implemented so it should now be mergeable. |
Tests are green and the Gemfile is cleaner now! |
Celebrate! |
Reverts part of bb25acf The issue was resolved: lostisland/faraday#619
This PR attempts to support Net::HTTP::Persistent 3.x or 2.x with its existing Faraday Adapter.
Changes introduced
ruby RUBY_VERSION
Ruby version hinting for Bundler in the Gemfile.TODO
parameters
instead ofNet::HTTP::Persistent::VERSION
to find out which version is runningOut of scope for this PR: