From 903033779972aff96839f37f378cd882ff44aca6 Mon Sep 17 00:00:00 2001 From: Cassondra Foesch Date: Wed, 7 Nov 2018 12:01:48 +0000 Subject: [PATCH 1/2] fix rare corner cases that can panic or block on channels --- checks/rabbitmq/check.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/checks/rabbitmq/check.go b/checks/rabbitmq/check.go index 5ab5f03..60470e8 100644 --- a/checks/rabbitmq/check.go +++ b/checks/rabbitmq/check.go @@ -94,12 +94,17 @@ func New(config Config) func() error { return err } - done := make(chan struct{}, 1) - defer close(done) + done := make(chan struct{}) go func() { + // block until: a message is received, or message channel is closed (consume timeout) + <-message + + // release the channel resources, and unblock the receive on done below + close(done) + + // now drain any incidental remaining messages for range messages { - done <- struct{}{} } }() From f1dd7f944e3c876adfe83581994232f1eeb64279 Mon Sep 17 00:00:00 2001 From: Cassondra Foesch Date: Wed, 7 Nov 2018 12:39:56 +0000 Subject: [PATCH 2/2] typo --- checks/rabbitmq/check.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checks/rabbitmq/check.go b/checks/rabbitmq/check.go index 60470e8..af11ad8 100644 --- a/checks/rabbitmq/check.go +++ b/checks/rabbitmq/check.go @@ -98,7 +98,7 @@ func New(config Config) func() error { go func() { // block until: a message is received, or message channel is closed (consume timeout) - <-message + <-messages // release the channel resources, and unblock the receive on done below close(done)