Skip to content
This repository was archived by the owner on Nov 28, 2018. It is now read-only.
This repository was archived by the owner on Nov 28, 2018. It is now read-only.

Stomp.on('error') Not Called for TLS Errors #27

Open
@joshuarubin

Description

@joshuarubin

The following code will cause node to terminate on a TLS authentication error:

var stomp = new Stomp(args);
stomp.on('error', function (err) {
  console.error("Stomp Error: " + err);
});
stomp.connect()

I had to add the following (immediately after connect()) to be able to catch it:

stomp.socket.on('error', function (err) {
  console.error("Stomp TLS Error: " + err);
});

The reason for this is due to this code in stomp.js

stomp.socket = tls.connect(stomp.port, stomp.host, stomp.ssl_options, function() {
    log.debug('SSL connection complete');
    if (!stomp.socket.authorized) {
        log.error('SSL is not authorized: '+stomp.socket.authorizationError);
        if (stomp.ssl_validate) {
            _disconnect(stomp);
            return;
        }
    }
    _setupListeners(stomp);
});

_setupListeners(stomp); is only called after tls.connect() succeeds, in the callback.

According to http://nodejs.org/api/tls.html#tls_tls_connect_port_host_options_callback

the callback parameter will be added as a listener for the 'secureConnect' event.

Since there is no socket.on('error') handler when tls.connect fails, stomp never catches the error and never, subsequently, emits its own error.

I did find the above workaround, but it seems that stomp.on('error') should have worked the first time.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions