Skip to content

Consumer send on closed channel after Cancel #27

Description

@cdeluce

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 ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions