This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tls: Closing parent socket also closes the tls sock
- Loading branch information
Showing
3 changed files
with
70 additions
and
11 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
if (!process.versions.openssl) { | ||
console.error('Skipping because node compiled without OpenSSL.'); | ||
process.exit(0); | ||
} | ||
|
||
var common = require('../common'); | ||
var assert = require('assert'); | ||
var tls = require('tls'); | ||
var fs = require('fs'); | ||
|
||
var options = { | ||
key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'), | ||
cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem') | ||
}; | ||
|
||
var normalSock = null; | ||
var hasError = false; | ||
var tlsCloseCount = 0; | ||
var sockCloseCount = 0; | ||
|
||
var server = tls.createServer(options, function(secureSock) { | ||
secureSock.on('error', function() { | ||
hasError = true; | ||
}); | ||
secureSock.on('close', function() { | ||
tlsCloseCount++; | ||
}); | ||
normalSock.on('close', function() { | ||
sockCloseCount++; | ||
}); | ||
|
||
normalSock.destroy(); | ||
secureSock.write('Test!', function(err) { | ||
assert(err); | ||
}); | ||
}); | ||
|
||
server.on('connection', function(sock){ | ||
normalSock = sock; | ||
}); | ||
|
||
server.listen(common.PORT, function() { | ||
var c = tls.connect(common.PORT, {rejectUnauthorized: false}); | ||
c.on('error', function() {}); // ignore socket hangup error | ||
|
||
c.on('end', function() { | ||
server.close(); | ||
}); | ||
|
||
process.on('exit', function(){ | ||
assert(hasError) | ||
assert.equal(tlsCloseCount, 1); | ||
assert.equal(sockCloseCount, 1); | ||
}); | ||
}); |