With certain hosts (and the particular cipher settings used below) tls.connect() appears to emit an error event twice.
var host='85.158.224.100';
var options = { rejectUnauthorized: false,
servername: host,
ciphers: 'EXPORT' };
require('tls').connect(443, host, options, function() {
console.log('success');
}).on('error', function(error) {
console.log(error);
console.log();
});
Actual Result
{ [Error: socket hang up] code: 'ECONNRESET' }
[Error: 101057795:error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handsh
ake failure:openssl\ssl\s3_pkt.c:1293:SSL alert number 40
101057795:error:140780E5:SSL routines:SSL23_READ:ssl handshake failure:openssl\s
sl\s23_lib.c:138:
]
Expected Result
[Error: 101057795:error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handsh
ake failure:openssl\ssl\s3_pkt.c:1293:SSL alert number 40
101057795:error:140780E5:SSL routines:SSL23_READ:ssl handshake failure:openssl\s
sl\s23_lib.c:138:
]
Quick assumption would be it has something to do with SNI, as it does not occur if servername is not set.