diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 95df8f56604682..0a30cd3310c1f1 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -289,15 +289,22 @@ TLSSocket.prototype._wrapHandle = function(handle) { } }); - this.on('close', this._destroySSL); + this.on('close', function() { + this._destroySSL(); + res = null; + }); return res; }; TLSSocket.prototype._destroySSL = function _destroySSL() { + if (!this.ssl) return; this.ssl.destroySSL(); - if (this.ssl._secureContext.singleUse) + if (this.ssl._secureContext.singleUse) { this.ssl._secureContext.context.close(); + this.ssl._secureContext.context = null; + } + this.ssl = null; }; TLSSocket.prototype._init = function(socket, wrap) {