Browse Source

Stop closing close and cancel channels

The channel takes ownership of those channels when
we call Notify*, so we should not be closing them
or a panic could happen due to double closure or
sending to a closed channel.
pull/29/head
Victor Elias 4 years ago
parent
commit
98f15aea03
1 changed files with 3 additions and 16 deletions
  1. +3
    -16
      channel.go

+ 3
- 16
channel.go View File

@ -53,10 +53,9 @@ func getNewChannel(url string, conf amqp.Config) (*amqp.Connection, *amqp.Channe
// backoff. Once reconnected, it sends an error back on the manager's notifyCancelOrClose // backoff. Once reconnected, it sends an error back on the manager's notifyCancelOrClose
// channel // channel
func (chManager *channelManager) startNotifyCancelOrClosed() { func (chManager *channelManager) startNotifyCancelOrClosed() {
notifyCloseChan := make(chan *amqp.Error)
notifyCloseChan = chManager.channel.NotifyClose(notifyCloseChan)
notifyCancelChan := make(chan string)
notifyCancelChan = chManager.channel.NotifyCancel(notifyCancelChan)
notifyCloseChan := chManager.channel.NotifyClose(make(chan *amqp.Error, 1))
notifyCancelChan := chManager.channel.NotifyCancel(make(chan string, 1))
select { select {
case err := <-notifyCloseChan: case err := <-notifyCloseChan:
// If the connection close is triggered by the Server, a reconnection takes place // If the connection close is triggered by the Server, a reconnection takes place
@ -72,18 +71,6 @@ func (chManager *channelManager) startNotifyCancelOrClosed() {
chManager.logger.Printf("successfully reconnected to amqp server after cancel") chManager.logger.Printf("successfully reconnected to amqp server after cancel")
chManager.notifyCancelOrClose <- errors.New(err) chManager.notifyCancelOrClose <- errors.New(err)
} }
// these channels can be closed by amqp
select {
case <-notifyCloseChan:
default:
close(notifyCloseChan)
}
select {
case <-notifyCancelChan:
default:
close(notifyCancelChan)
}
} }
// reconnectWithBackoff continuously attempts to reconnect with an // reconnectWithBackoff continuously attempts to reconnect with an


Loading…
Cancel
Save