From 7430c7f1f5cdb47c02f11a75d47fc39401e6c987 Mon Sep 17 00:00:00 2001 From: Michal Horejsek Date: Thu, 3 Sep 2020 08:47:35 +0200 Subject: [PATCH] Timeout for sending IMAP update --- internal/store/change.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/store/change.go b/internal/store/change.go index d4722a45..ee58e5bb 100644 --- a/internal/store/change.go +++ b/internal/store/change.go @@ -123,8 +123,16 @@ func (store *Store) imapSendUpdate(update imapBackend.Update) { } done := update.Done() - go func() { store.imapUpdates <- update }() + go func() { + // This timeout is to not keep running many blocked goroutines. + // In case nothing listens to this channel, this thread should stop. + select { + case store.imapUpdates <- update: + case <-time.After(1 * time.Second): + } + }() + // This timeout is to not block IMAP backend by wait for IMAP client. select { case <-done: case <-time.After(1 * time.Second):