diff options
author | jBarz <jbarboza@ca.ibm.com> | 2017-03-09 16:33:59 +0300 |
---|---|---|
committer | Italo A. Casas <me@italoacasas.com> | 2017-03-20 17:18:34 +0300 |
commit | 540830116be5617cfd02407fecda2e6941f35296 (patch) | |
tree | 473a771b376c4f572ade19c8848590ab18fa7e4f /test | |
parent | 9a5991303944d7cb8a1af9a2d97d3342b4762e0e (diff) |
tls: keep track of stream that is closed
TLSWrap object keeps a pointer reference to the underlying
TCPWrap object. This TCPWrap object could be closed and deleted
by the event-loop which leaves us with a dangling pointer.
So the TLSWrap object needs to track the "close" event on the
TCPWrap object.
PR-URL: https://github.com/nodejs/node/pull/11776
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-tls-socket-close.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/parallel/test-tls-socket-close.js b/test/parallel/test-tls-socket-close.js new file mode 100644 index 00000000000..440c0c4ff7c --- /dev/null +++ b/test/parallel/test-tls-socket-close.js @@ -0,0 +1,43 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); + +const tls = require('tls'); +const fs = require('fs'); +const net = require('net'); + +const key = fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'); +const cert = fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'); + +const T = 100; + +// tls server +const tlsServer = tls.createServer({ cert, key }, (socket) => { + setTimeout(() => { + socket.on('error', (error) => { + assert.strictEqual(error.code, 'EINVAL'); + tlsServer.close(); + netServer.close(); + }); + socket.write('bar'); + }, T * 2); +}); + +// plain tcp server +const netServer = net.createServer((socket) => { + // if client wants to use tls + tlsServer.emit('connection', socket); + + socket.setTimeout(T, () => { + // this breaks if TLSSocket is already managing the socket: + socket.destroy(); + }); +}).listen(0, common.mustCall(function() { + + // connect client + tls.connect({ + host: 'localhost', + port: this.address().port, + rejectUnauthorized: false + }).write('foo'); +})); |