I have the following Javascript code which shows a different behaviour depending on whether you run it against a HTTP or HTTPS endpoint.
var url=require('url').parse(process.argv[2]);
var secure=url.protocol.indexOf('https')===0;
var socket=new require('net').Socket();
socket.setTimeout(2000, function() {
this.destroy();
console.log('TCP connection timed out');
});
socket.connect({ host: url.hostname, port: url.port || (secure?443:80) }, function() {
if (secure)
{
require('tls').connect({ socket: this, rejectUnauthorized: false, servername: url.hostname }, function() {
this.destroy();
console.log('SSL successfully connected');
}).on('error', function(error){
this.destroy();
console.log('Error during SSL handshake');
});
}
else
{
this.destroy();
console.log('Non-SSL successfully connected');
}
}).on('error', function(error) {
this.destroy();
console.log('Error during TCP connection '+error.code);
});
// Just a dummy listener to keep node from exiting
require('http').createServer().listen(2000);
Everything is fine in the case of a regular HTTP connection everything, however switching to HTTPS the timeout handler will be called regardless.
From what I debugged it might happen because I am not closing the socket itself but the TLS wrapper socket object. Could this be the reason or could it be a bug in node.js (and io.js, it started happening only recently with node.js 0.12 and io.js 1.2).
Aucun commentaire:
Enregistrer un commentaire