Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

TLSSocket.destroy() is not fully closing the socket #9242

Description

@user447463

node 0.12 seems to have introduced a timeout related issue for the TLS package. Closing the TLSSocket is not enough to stop the timeout but an additional TCP socket close is necessary.

Please see the following code sample for a reproducible pattern (0.10 vs. 0.12)

var url=require('url').parse(process.argv[2]);
var secure=url.protocol=='https:';

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);
});

// Dummy line to keep node from exiting
setInterval(function() {}, 1000);

Expected result

node file.js https://www.google.com
SSL successfully connected

Actual result

node file.js https://www.google.com
SSL successfully connected
TCP connection timed out

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions