Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consumer send on closed channel after Cancel #27

Open
cdeluce opened this issue Oct 2, 2017 · 3 comments
Open

Consumer send on closed channel after Cancel #27

cdeluce opened this issue Oct 2, 2017 · 3 comments

Comments

@cdeluce
Copy link

cdeluce commented Oct 2, 2017

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
Copy link

sadf

@peczenyj
Copy link

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

@nikonor
Copy link

nikonor commented Jan 29, 2020

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants