From 98f15aea034aba9ac51427798a1232c569673983 Mon Sep 17 00:00:00 2001 From: Victor Elias Date: Mon, 12 Jul 2021 21:44:56 -0300 Subject: [PATCH] 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. --- channel.go | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/channel.go b/channel.go index 3ced887..3f2c598 100644 --- a/channel.go +++ b/channel.go @@ -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 // channel 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 { case err := <-notifyCloseChan: // 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.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