Skip to content

Impossible to catch error during tls.connect(duplex) #29678

Open
@Qualtagh

Description

@Qualtagh
  • Version: 10.16.3
  • Platform: Ubuntu 16.04.1
  • Subsystem: tls

There seems to be no way to catch synchronous error of underlying duplex stream during tls.connect operation.
Code sample:

const stream = require('stream');
const tls = require('tls');

const async = false;
process.on('uncaughtException', e=>console.log('uncaught: '+e));

const socket = new stream.Duplex({
    read(size){},
    write(data, encoding, cb){
        let error = new Error('intended error');
        if (async)
            setTimeout(()=>cb(error), 1000);
        else
            cb(error);
    },
});
socket.on('error', e=>console.log('socket error: '+e));

const tls_socket = tls.connect({socket});
tls_socket.on('error', e=>console.log('tls_socket error: '+e));

Expected output:

socket error: Error: intended error
tls_socket error: Error: intended error

Actual output:

socket error: Error: intended error
uncaught: Error: intended error

Changing async to true solves the issue.
Can we allow passing onError handler to tls.connect method? So, it will be set before calling _start() method of TLSSocket.

Metadata

Metadata

Assignees

No one assigned

    Labels

    tlsIssues and PRs related to the tls subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions