From f043fdccb847ad43a63c7de8c5dc8f4f929955f0 Mon Sep 17 00:00:00 2001 From: Jeff Principe Date: Fri, 5 Feb 2021 14:57:11 -0800 Subject: [PATCH] Unblock receiver goroutine on shutdown --- changelog.md | 3 +++ receiver.go | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index b1c4e2ad..bbcfbf49 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # Change Log +## `v3.3.6` +- fix goroutine leak on listener close + ## `v3.3.5` - Remove the check for temporary network errors in sender.go [#80](https://github.com/Azure/azure-event-hubs-go/issues/80) diff --git a/receiver.go b/receiver.go index 2fb09a09..581ab128 100644 --- a/receiver.go +++ b/receiver.go @@ -287,8 +287,15 @@ func (r *receiver) listenForMessages(ctx context.Context, msgChan chan *amqp.Mes for { msg, err := r.listenForMessage(ctx) if err == nil { - msgChan <- msg - continue + select { + case msgChan <- msg: + // Sent + continue + case <-ctx.Done(): + // Context canceled before send, ignore and shut down + tab.For(ctx).Debug("context done") + return + } } select {