using connection callback results in double exchange channel open #139

DavidIAm opened this Issue Oct 18, 2012 · 0 comments


None yet
1 participant

When I use the connection ready callback as a parameter on the createConnection call instead of listening for the 'ready' event., my callback code initiates a channel open from connecting to an exchange before the constructor's 'ready' callback is activated. Since the reconnect option is 'true', and the channels array has entries, it then tries to open the just previously opened channel even though it is already open, which is a protocol violation and crashes the amqp connection.

This could probably be avoided by having the this._readyCallback activated in the 'ready' event handler, so that its impossible for any code to wedge itself in and open a channel before the main ready event handler is processed.

The code that calls the ready callback before emitting/processing the ready event:

1108 case methods.connectionOpenOk:
1109 // 7. Finally they respond with connectionOpenOk
1110 // Whew! That's why they call it the Advanced MQP.
1111 if (this._readyCallback) {
1112 this._readyCallback(this);
1113 this._readyCallback = null;
1114 }
1115 this.emit('ready');
1116 break;

The code that reconnects to the channel array when there is a ready event:

940 self.addListener('ready', function () {
941 // Reset the backoff time since we have successfully connected.
942 backoffTime = null;
944 if (self.implOptions.reconnect) {
945 // Reconnect any channels which were open.
946 for (var channel in self.channels) {
947 if (channel != 0) {
948 self.channels[channel].reconnect();
949 }
950 }
951 }
953 // Restart the heartbeat to the server
954 self._outboundHeartbeatTimerReset();
955 })

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