From c6486ad061d15be21c148e7e20a92153a69a12b7 Mon Sep 17 00:00:00 2001 From: Tony An Date: Mon, 9 Jan 2023 02:50:06 -0800 Subject: [PATCH] :bug: close publisher properly to prevent resource leaks --- publish.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/publish.go b/publish.go index b361f84..8779a0e 100644 --- a/publish.go +++ b/publish.go @@ -191,6 +191,12 @@ func (publisher *Publisher) Publish( // The publisher should be discarded as it's not safe for re-use // Only call Close() once func (publisher *Publisher) Close() { + // close the channel so that rabbitmq server knows that the + // publisher has been stopped. + err := publisher.chanManager.Close() + if err != nil { + publisher.options.Logger.Warnf("error while closing the channel: %v", err) + } publisher.options.Logger.Infof("closing publisher...") go func() { publisher.closeConnectionToManagerCh <- struct{}{}