-
Notifications
You must be signed in to change notification settings - Fork 978
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
NetHttpPersistent adapter reuse SSL connections #793
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 giving this shot!
You can probably use the object_id
for cert_store
and other incomparable fields as ssl_options shouldn't really change between requests.
I also left a couple of comments as some things are not clear to me.
def cached_connection(url, proxy_uri) | ||
(@cached_connection ||= {})[[url.scheme, url.host, url.port, proxy_uri]] ||= yield | ||
def http_set(http, attr, value) | ||
if http.sent(attr) != value |
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 should probably be send
?
end | ||
|
||
def cached_connection | ||
@cached_connection ||= yield |
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.
Removing the hash caching, we're going to reuse the same connection even though the url changes. Or am I missing something?
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.
Net::HTTP::Persistent
has logic for using different connections for different URI bases (including differences in proxy) internally.
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.
cert_store | ||
@cert_store = OpenSSL::X509::Store.new | ||
@cert_store.set_default_paths | ||
@cert_store |
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.
Found the issue. object_id
comparison wasn't working because the NetHttp
adapter was newing up a cert store every time. This memoizes it.
I think this is working now. we'll see what CI has to say though. |
@iMacTia Any thoughts on the updates? |
I’m really sorry @katsuya94, really wanted to have another look but I still haven’t got the time :( |
No worries! Take your time. |
@katsuya94 I had a quick look at changes and they look good to me! The only thing I'm not completely sure about is the comeback on relying on I would like to re-run the same tests @grosser did on that PR to see if we're regressing on that side. |
net-http-persistent 2.9.4
net-http-persistent 3.0.0
|
@katsuya94 Thanks for running the tests! |
end | ||
|
||
def cached_connection(url, proxy_uri) | ||
(@cached_connection ||= {})[[url.scheme, url.host, url.port, proxy_uri]] ||= yield | ||
def cached_connection |
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.
might as well inline it at that point :)
Description
Fixes #791 by only setting SSL attributes on the
Net::HTTP::Persistent
instance when params are changed.@iMacTia this is a (not working yet) first stab at fixing the issue. The problem I'm running into is in order to determine when to actually update SSL params I need to compare the current and new values. Unfortunately some of these values like
cert_store
are of non-comparable types likeOpenSSL::X509::Store
. Any ideas?Update: fixed issues with object comparison by caching the blank cert store.