ruby-amqp/amqp — Issue #111: 0.7.x AMQP::Queue#reset may cause channel error
Author: samstokes
Created: 2011-10-21 00:09:15+00:00
State: open

AMQP::Queue#reset (in amqp/queue.rb) calls #unsubscribe - which sets a callback to cancel the queue subscription - and then, before the callback fires, synchronously clears out the Queue instance variables in order to resubscribe. When the unsubscribe callback fires, depending on the order in which the callbacks fire, it may send the Basic::Cancel with a consumer_tag of nil, which results in the following channel error:

"Basic.CancelOk for invalid consumer tag: "

I can reproduce this fairly reliably when setting a client heartbeat (`:heartbeat => 5`) and having a long-running synchronous call in the subscribe block cause the client to "miss" heartbeats.

I'm not sure what would be the correct fix. I tried modifying #unsubscribe to save the values of `@mq` and `@consumer_tag` in local variables before firing the callback, but then the new channel seems to receive the CancelOk for the old channel's consumer_tag, which also causes a channel error.