-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #11776 Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Brian White <[email protected]>
- Loading branch information
1 parent
ba91c41
commit 99749dc
Showing
4 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
})); |