| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent abbf6e3 commit 485bb1b
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,35 +9,46 @@ const net = require('net'); | |||
| 9 | 9 | const key = fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'); | |
| 10 | 10 | const cert = fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'); | |
| 11 | 11 | ||
| 12 | - const T = 100; | ||
| 13 | - | ||
| 12 | + let tlsSocket; | ||
| 14 | 13 | // tls server | |
| 15 | 14 | const tlsServer = tls.createServer({ cert, key }, (socket) => { | |
| 16 | - setTimeout(() => { | ||
| 17 | - socket.on('error', (error) => { | ||
| 18 | - assert.strictEqual(error.code, 'EINVAL'); | ||
| 19 | - tlsServer.close(); | ||
| 20 | - netServer.close(); | ||
| 21 | - }); | ||
| 22 | - socket.write('bar'); | ||
| 23 | - }, T * 2); | ||
| 15 | + tlsSocket = socket; | ||
| 16 | + socket.on('error', common.mustCall((error) => { | ||
| 17 | + assert.strictEqual(error.code, 'EINVAL'); | ||
| 18 | + tlsServer.close(); | ||
| 19 | + netServer.close(); | ||
| 20 | + })); | ||
| 24 | 21 | }); | |
| 25 | 22 | ||
| 23 | + let netSocket; | ||
| 26 | 24 | // plain tcp server | |
| 27 | 25 | const netServer = net.createServer((socket) => { | |
| 28 | - // if client wants to use tls | ||
| 26 | + // if client wants to use tls | ||
| 29 | 27 | tlsServer.emit('connection', socket); | |
| 30 | 28 | ||
| 31 | - socket.setTimeout(T, () => { | ||
| 32 | - // this breaks if TLSSocket is already managing the socket: | ||
| 33 | - socket.destroy(); | ||
| 34 | - }); | ||
| 29 | + netSocket = socket; | ||
| 35 | 30 | }).listen(0, common.mustCall(function() { | |
| 36 | - | ||
| 37 | 31 | // connect client | |
| 38 | 32 | tls.connect({ | |
| 39 | 33 | host: 'localhost', | |
| 40 | 34 | port: this.address().port, | |
| 41 | 35 | rejectUnauthorized: false | |
| 42 | - }).write('foo'); | ||
| 36 | + }).write('foo', 'utf8', common.mustCall(() => { | ||
| 37 | + assert(netSocket); | ||
| 38 | + netSocket.setTimeout(1, common.mustCall(() => { | ||
| 39 | + assert(tlsSocket); | ||
| 40 | + // this breaks if TLSSocket is already managing the socket: | ||
| 41 | + netSocket.destroy(); | ||
| 42 | + const interval = setInterval(() => { | ||
| 43 | + // Checking this way allows us to do the write at a time that causes a | ||
| 44 | + // segmentation fault (not always, but often) in Node.js 7.7.3 and | ||
| 45 | + // earlier. If we instead, for example, wait on the `close` event, then | ||
| 46 | + // it will not segmentation fault, which is what this test is all about. | ||
| 47 | + if (tlsSocket._handle._parent.bytesRead === 0) { | ||
| 48 | + tlsSocket.write('bar'); | ||
| 49 | + clearInterval(interval); | ||
| 50 | + } | ||
| 51 | + }, 1); | ||
| 52 | + })); | ||
| 53 | + })); | ||
| 43 | 54 | })); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments