assembla / cony

Simple AMQP wrapper around github.com/streadway/amqp
BSD 2-Clause "Simplified" License
174 stars 46 forks source link

Consumer send on closed channel after Cancel #27

Open cdeluce opened 7 years ago

cdeluce commented 7 years ago

Hi,

I got multiple errors when trying to close a Consumer using Cancel: The c.deliveries channel is closed in the Cancel method, but than the serve method, because of the randomness of select, sometimes tries to write in this channel before running the c.close case. The program crashes because of this.

Here is an extract of my program (sigs is closed when I receive a signal):

for rmqConnector.Loop() {
  select {
    case msg := <-rmqConsumer.Deliveries():
      messageChan <- msg.Body
    case err := <-rmqConsumer.Errors():
      fmt.Printf("Consumer error: %v\n", err)
    case err := <-rmqConnector.Errors():
      fmt.Printf("Client error: %v\n", err)
    case _, open := <-sigs:
      if !open {
        rmqConsumer.Cancel()
        return
      }
   }
}

When canceling, I get a "panic: send on closed channel" at consumer.go line 92, called from client.go line 188.

Am I using this wrong ? Maybe moving

close(c.deliveries)

from

if !c.dead {
  close(c.deliveries)
  close(c.stop)
  c.dead = true
}

to

select {
  case <-c.stop:
    client.deleteConsumer(c)
    ch.Close()
    return

would fix it ?

kolorowestudio commented 5 years ago

sadf

peczenyj commented 5 years ago

In fact I have the same issue, any news about this?

nikonor commented 4 years ago

+1