-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
https: reuse TLS sessions in Agent #2228
Conversation
cc @nodejs/crypto @nodejs/collaborators |
if (options._agentKey && this._tlsSessions[options._agentKey]) { | ||
debug('reuse session for %j', options._agentKey); | ||
options = util._extend({ | ||
session: this._tlsSessions[options._agentKey] |
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.
If session
is the only one being set, maybe it is worth it to just use options.session = options.session || ...
?
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.
Yeah, but we usually try to avoid changing the objects that are passed to the function.
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 think we already make a copy, that's why I'm asking. :) Not trying to be a stickler - you could say that call and I go back a little bit.
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.
Haha, I'd leave it as it is. Performance impact is minimal here.
Can this cause a memory leak for servers that make a lot of TLS connections to different servers? |
@brendanashworth good catch! I'll revise it tomorrow |
@brendanashworth added limit ;) |
Any further comments @brendanashworth ? cc @bnoordhuis @shigeki ;) |
@indutny 'tis cool and a great improvement on before :) but I'm not comfortable reviewing, too complicated - no further comments. Can't wait to see this merged! |
// Unless server has resumed our existing session | ||
if (!verifyError && | ||
(!options.session || | ||
Buffer.compare(options.session, socket.getSession()) !== 0)) { |
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.
FWIW Buffer.compare()
is still fairly slow right now and using a manual for-loop in js land is faster.
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 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.
Isn't there an edge case if socket.getSession()
returns null?
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.
Good point, @shigeki !
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.
After some consideration - I don't think that it might be the case at this point in runtime. But I will add guard just in case.
I made several tests with/without resumption against my https server and confirmed this works fine. Good job. I put small comments for fix but LGTM. |
Thanks everyone! May I ask you to take one last look at this before I'll land it? |
if (!next) | ||
return false; | ||
|
||
return Buffer.compare(session, next) === 0; |
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.
don't care if you make this change, but could use return session.equals(next);
(assuming they're both buffers).
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.
Good point. I'll use next.equals()
here.
Fix: nodejs#1499 PR-URL: nodejs#2228 Reviewed-By: Shigeki Ohtsu <ohtsu@iij.ad.jp> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
@trevnorris fixed |
LGTM |
Landed in 2ca5a3d, thank you everyone! |
PR-URL: nodejs#26433 Refs: nodejs#2228 Refs: nodejs#4252 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
PR-URL: nodejs#26433 Refs: nodejs#2228 Refs: nodejs#4252 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Fix: #1499