mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -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
54e8845b5e
commit
101de9de3f
2 files changed
+104
No files matched your search
@@ -83,6 +83,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;
|
||||
}
|
||||
|
||||
@@ -163,6 +170,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