TLSSocket.destroy() and its underlying TCP socket

56 views
Skip to first unread message

alessio b

unread,
Feb 17, 2015, 2:03:15 PM2/17/15
to nod...@googlegroups.com
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('https://anyserver'); // Change here to http to reproduce the difference
        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, 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 the library (it started happening only recently after the upgrade from 0.10 to 0.12).

alessio b

unread,
Feb 18, 2015, 3:44:20 AM2/18/15
to nod...@googlegroups.com
Nobody would have an idea whats going on?

I really somewhat puzzled, as - from my understanding - the return value of tls.connect() should be semantically identical to net.connect() and hence its destroy() method should equally close the socket and stop the timeout timer.

Fedor Indutny

unread,
Feb 18, 2015, 2:19:17 PM2/18/15
to nod...@googlegroups.com
Hello!

Please file a bug here: https://github.com/iojs/io.js/issues

Cheers,
Fedor.

On Wed, Feb 18, 2015 at 9:44 AM, alessio b <ales...@gmail.com> wrote:
Nobody would have an idea whats going on?

I really somewhat puzzled, as - from my understanding - the return value of tls.connect() should be semantically identical to net.connect() and hence its destroy() method should equally close the socket and stop the timeout timer.

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/d2427d87-d76c-43fc-b783-340c17283de2%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages