amqp / rhea-promise

A promisified layer over rhea AMQP client
Apache License 2.0
31 stars 19 forks source link

'undefined' thrown as exception in connection.open() when server connections exceeded #26

Closed swilliams-a3digital closed 5 years ago

swilliams-a3digital commented 5 years ago

In our code we call connection.open to open a connection. If the server has exceeded the maxNumber of allowed connections, this method correctly throws an exception when it fails to connect, but the content of the exception is incorrect. 'undefined' is thrown, rather than a proper Error.

The expected behavior is an Error is thrown with message ('failed to connect') or something like that.

To Reproduce Setup an active mq message server and restrict max number of connections to something low. e.g.

On the 11th connection created connection.open will fail and throw an exception, and the exception thrown will equal undefined.

Expected behavior exception is an Error. It is non standard to throw undefined.

package version: "rhea": "^0.3.9", "rhea-promise": "^0.1.13"

node.js version: v8.11.2 OS name and version: MAC OS 10.13.6 (happens on other OS too)

Additional context setting ENV VAR DEBUG=rhea* . Yields and endless stream of disconnected events:

rhea-promise:translate [connection-1] Translating the context for event: 'disconnected'. +113ms rhea:reconnect [connection-1] reconnecting... +102ms rhea:io [connection-1] connected 127.0.0.1:49750 -> 127.0.0.1:5672 +108ms rhea:frames [connection-1] -> { protocol_id: 3, major: 1, minor: 0, revision: 0 } +108ms rhea:reconnect [connection-1] Scheduled reconnect in 100ms +4ms rhea:events [connection-1] Connection got event: disconnected +105ms rhea-promise:connection [connection-1] connection got event: 'disconnected'. Re-emitting the translated context. +105ms rhea-promise:translate [connection-1] Translating the context for event: 'disconnected'. +105ms rhea:reconnect [connection-1] reconnecting... +103ms rhea:io [connection-1] connected 127.0.0.1:49754 -> 127.0.0.1:5672 +107ms rhea:frames [connection-1] -> { protocol_id: 3, major: 1, minor: 0, revision: 0 } +107ms rhea:reconnect [connection-1] Scheduled reconnect in 100ms +4ms rhea:events [connection-1] Connection got event: disconnected +107ms

swilliams-a3digital commented 5 years ago

if I set DEBUG=rhea_promise, I see this:

rhea-promise:error [connection-1] Error occurred while establishing amqp connection: undefined +0ms

swilliams-a3digital commented 5 years ago

I believe the source of the error is in connection.ts: onClose = (context: RheaEventContext) => { removeListeners(); const err = context.error || context.connection.error; log.error("[%s] Error occurred while establishing amqp connection: %O", this.id, err); return reject(err); }; const err = context.error || context.connection.error; ==> this resolves to undefined

swilliams-a3digital commented 5 years ago

I will give a pull request a whirl to suggest a fix.