gmr / rabbitpy

A pure python, thread-safe, minimalistic and pythonic RabbitMQ client library
http://rabbitpy.readthedocs.org
BSD 3-Clause "New" or "Revised" License
242 stars 58 forks source link

Re-use channel ids? #121

Open eandersson opened 4 years ago

eandersson commented 4 years ago

I remember troubleshooting a bug report for amqpstorm and looking at rabbitpy as a reference at the time I believe that it suffers from the same issue https://github.com/eandersson/amqpstorm/issues/55

I believe that we should be re-using the id of previously closed channels. This is at least what pika does, and has been working great for amqpstorm.

eblis commented 3 years ago

I think we've hit a problem with the way RabbitPy uses channels and their IDs.

We have a piece of code that connects to a RabbitMQ instance and receives a message - it does so by creating a new channel then, when the processing is done closing everything (uses the channel in a with statement) The problem is that after about 1024 or 2048 calls RabbitPy crashes saying that there are too many channels.

The relevant piece of code is this:

        if not self._channels:
            return 1
        if self._max_channel_id == self._channel0.maximum_channels:
            raise exceptions.TooManyChannelsError
        return self._max_channel_id + 1

I can see that the max_channel_id is incremented when a new channel is created but I don't see it ever getting decremented. Shouldn't the max_channel_id go down if a channel is no longer used ? Should the max_channel_id be allowed to go over the maximum_channels value as long as open channels count is still below ?