-
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: emit errors happening before handshake finish
This fixes a race condition introduced in 80342f6. `socket.destroy(err)` only emits the passed error when `socket._writableState.errorEmitted === false`, `ssl.onerror` sets `errorEmitted = true` just before calling `socket.destroy()`. See: #1119 See: #1711 PR-URL: #1769 Reviewed-By: Fedor Indutny <[email protected]>
- Loading branch information
Showing
2 changed files
with
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
|
||
var assert = require('assert'); | ||
var common = require('../common'); | ||
|
||
if (!common.hasCrypto) { | ||
console.log('1..0 # Skipped: missing crypto'); | ||
process.exit(); | ||
} | ||
var tls = require('tls'); | ||
|
||
var fs = require('fs'); | ||
var net = require('net'); | ||
|
||
var errorCount = 0; | ||
var closeCount = 0; | ||
|
||
var server = tls.createServer({ | ||
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), | ||
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'), | ||
rejectUnauthorized: true | ||
}, function(c) { | ||
}).listen(common.PORT, function() { | ||
var c = tls.connect({ | ||
port: common.PORT, | ||
ciphers: 'RC4' | ||
}, function() { | ||
assert(false, 'should not be called'); | ||
}); | ||
|
||
c.on('error', function(err) { | ||
errorCount++; | ||
assert.notEqual(err.code, 'ECONNRESET'); | ||
}); | ||
|
||
c.on('close', function(err) { | ||
if (err) | ||
closeCount++; | ||
server.close(); | ||
}); | ||
}); | ||
|
||
process.on('exit', function() { | ||
assert.equal(errorCount, 1); | ||
assert.equal(closeCount, 1); | ||
}); |