From f7aa2f6b258d2a586fae1c2a780fedaadffbe19e Mon Sep 17 00:00:00 2001 From: Livio Amstutz Date: Fri, 9 Jul 2021 11:33:43 +0200 Subject: [PATCH] fix: handle closed channels on unsubscribe (#1995) --- internal/eventstore/subscription.go | 5 ++++- internal/eventstore/v1/subscription.go | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/eventstore/subscription.go b/internal/eventstore/subscription.go index 13d26cb02..6a8af4832 100644 --- a/internal/eventstore/subscription.go +++ b/internal/eventstore/subscription.go @@ -69,7 +69,10 @@ func (s *Subscription) Unsubscribe() { } } } - close(s.Events) + _, ok := <-s.Events + if ok { + close(s.Events) + } } func MapEventsToV1Events(events []EventReader) []*models.Event { diff --git a/internal/eventstore/v1/subscription.go b/internal/eventstore/v1/subscription.go index ed5596ba7..2cde87e8b 100644 --- a/internal/eventstore/v1/subscription.go +++ b/internal/eventstore/v1/subscription.go @@ -67,5 +67,8 @@ func (s *Subscription) Unsubscribe() { } } } - close(s.Events) + _, ok := <-s.Events + if ok { + close(s.Events) + } }