cony icon indicating copy to clipboard operation
cony copied to clipboard

Consumer send on closed channel after Cancel

Open cdeluce opened this issue 8 years ago • 3 comments

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 ?

cdeluce avatar Oct 02 '17 14:10 cdeluce

sadf

kolorowestudio avatar Jul 25 '19 08:07 kolorowestudio

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

peczenyj avatar Oct 18 '19 13:10 peczenyj

+1

nikonor avatar Jan 29 '20 12:01 nikonor