mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
https: evict cached sessions on error
Instead of using the same session over and over, evict it when the socket emits error. This could be used as a mitigation of #3692, until OpenSSL fix will be merged/released. See: https://github.com/nodejs/node/issues/3692 PR-URL: https://github.com/nodejs/node/pull/4982 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Shigeki Ohtsu <ohtsu@iij.ad.jp>
This commit is contained in:
1 parent
5b7246e1be
commit
51941a1aa5
2 files changed
+104
No files matched your search
@@ -76,6 +76,13 @@ function createConnection(port, host, options) {
|
||||
|
||||
self._cacheSession(options._agentKey, socket.getSession());
|
||||
});
|
||||
|
||||
// Evict session on error
|
||||
socket.once('close', (err) => {
|
||||
if (err)
|
||||
this._evictSession(options._agentKey);
|
||||
});
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
@@ -152,6 +159,15 @@ Agent.prototype._cacheSession = function _cacheSession(key, session) {
|
||||
this._sessionCache.map[key] = session;
|
||||
};
|
||||
|
||||
Agent.prototype._evictSession = function _evictSession(key) {
|
||||
const index = this._sessionCache.list.indexOf(key);
|
||||
if (index === -1)
|
||||
return;
|
||||
|
||||
this._sessionCache.list.splice(index, 1);
|
||||
delete this._sessionCache.map[key];
|
||||
};
|
||||
|
||||
const globalAgent = new Agent();
|
||||
|
||||
exports.globalAgent = globalAgent;
|
||||
|
||||
Reference in new issue
Block a user