-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Description
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()
returnwould fix it ?
Metadata
Metadata
Assignees
Labels
No labels