rack-rabbit icon indicating copy to clipboard operation
rack-rabbit copied to clipboard

Temp (response) queue won't be auto-deleted due to channel remains open

Open starkovv opened this issue 9 years ago • 1 comments

Am I right thinking that RR::Client#request

https://github.com/jakesgordon/rack-rabbit/blob/0fc9fb8dc0dff3837d3376bf2adf7505be6a9981/lib/rack-rabbit/client.rb#L50

does not close channel after it received response?

So the temporary queue won't be auto-deleted, as the connection (channel) is still open.

starkovv avatar Apr 13 '15 18:04 starkovv

After some research I found out that rack-rabbit uses single channel for all its temp (response) queues.

On every sync request that rack-rabbit does, it creates temporary queue on RabbitMQ broker, and tells the broker to auto-destroy this queue right after the channel/connection to the broker will be closed.

It's fine if you instantiate new TCP connection to RabbitMQ every time you make synchronous request. So connection opened, temp queue created, actual request sent to exchange, response received from temp queue, connection closed, broker auto-deleted temp queue due to connection closed event. Done.

However, when you prefer to increase throughput and efficiency of your connection to RabbitMQ (in my case I've got 2x increase in throughput this way) and keep TCP connection open for further synchronous requests, that opened channel becomes a source of problems.

By keeping channel open, RabbitMQ does not see any reason to auto-delete created temp queue, so the temp queue for every request made will stay alive permanently. Thus, RabbitMQ will keep created and used temp queues until it overflow at some point.

To deal with this issue we need to manually delete temp queue right after we receive response from that queue.

To fix this it needs to add reply_queue.delete(if_empty: true) right before this line https://github.com/jakesgordon/rack-rabbit/blob/0fc9fb8dc0dff3837d3376bf2adf7505be6a9981/lib/rack-rabbit/client.rb#L65

Pull request will follow.

starkovv avatar Apr 14 '15 13:04 starkovv