diff --git a/amqpstorm/connection.py b/amqpstorm/connection.py index e499bfd6..5a1c311f 100644 --- a/amqpstorm/connection.py +++ b/amqpstorm/connection.py @@ -267,19 +267,12 @@ def _get_next_available_channel_id(self): :rtype: int """ - num_channels = len(self._channels) + 1 - if num_channels == self.max_allowed_channels: - raise AMQPConnectionError( - 'reached the maximum number of channels %d' % - self.max_allowed_channels) - - if num_channels <= self.max_allowed_channels: - return num_channels - - for index in compatibility.RANGE(1, num_channels): + for index in compatibility.RANGE(1, self.max_allowed_channels): if index in self._channels: continue return index + raise AMQPConnectionError('reached the maximum number of channels %d' % + self.max_allowed_channels) def _handle_amqp_frame(self, data_in): """Unmarshal a single AMQP frame and return the result.