| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8d985c2 commit 9cb236f
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -305,14 +305,31 @@ proxiedMethods.forEach(function(name) { | |||
| 305 | 305 | }); | |
| 306 | 306 | ||
| 307 | 307 | tls_wrap.TLSWrap.prototype.close = function close(cb) { | |
| 308 | - if (this.owner) | ||
| 308 | + let ssl; | ||
| 309 | + if (this.owner) { | ||
| 310 | + ssl = this.owner.ssl; | ||
| 309 | 311 | this.owner.ssl = null; | |
| 312 | + } | ||
| 313 | + | ||
| 314 | + // Invoke `destroySSL` on close to clean up possibly pending write requests | ||
| 315 | + // that may self-reference TLSWrap, leading to leak | ||
| 316 | + const done = () => { | ||
| 317 | + if (ssl) { | ||
| 318 | + ssl.destroySSL(); | ||
| 319 | + if (ssl._secureContext.singleUse) { | ||
| 320 | + ssl._secureContext.context.close(); | ||
| 321 | + ssl._secureContext.context = null; | ||
| 322 | + } | ||
| 323 | + } | ||
| 324 | + if (cb) | ||
| 325 | + cb(); | ||
| 326 | + }; | ||
| 310 | 327 | ||
| 311 | 328 | if (this._parentWrap && this._parentWrap._handle === this._parent) { | |
| 312 | - this._parentWrap.once('close', cb); | ||
| 329 | + this._parentWrap.once('close', done); | ||
| 313 | 330 | return this._parentWrap.destroy(); | |
| 314 | 331 | } | |
| 315 | - return this._parent.close(cb); | ||
| 332 | + return this._parent.close(done); | ||
| 316 | 333 | }; | |
| 317 | 334 | ||
| 318 | 335 | TLSSocket.prototype._wrapHandle = function(wrap) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,26 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + | ||
| 4 | + if (!common.hasCrypto) { | ||
| 5 | + common.skip('missing crypto'); | ||
| 6 | + return; | ||
| 7 | + } | ||
| 8 | + | ||
| 9 | + const assert = require('assert'); | ||
| 10 | + const net = require('net'); | ||
| 11 | + const tls = require('tls'); | ||
| 12 | + | ||
| 13 | + const server = net.createServer(common.mustCall((c) => { | ||
| 14 | + c.destroy(); | ||
| 15 | + })).listen(0, common.mustCall(() => { | ||
| 16 | + const c = tls.connect({ port: server.address().port }); | ||
| 17 | + c.on('error', () => { | ||
| 18 | + // Otherwise `.write()` callback won't be invoked. | ||
| 19 | + c.destroyed = false; | ||
| 20 | + }); | ||
| 21 | + | ||
| 22 | + c.write('hello', common.mustCall((err) => { | ||
| 23 | + assert.equal(err.code, 'ECANCELED'); | ||
| 24 | + server.close(); | ||
| 25 | + })); | ||
| 26 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments