From 5d1b64c3a41084a60b73192e2a54b2b7a3c6fc8d Mon Sep 17 00:00:00 2001 From: zhouliang Date: Thu, 26 Feb 2026 02:35:28 +0800 Subject: [PATCH] feat: add checkEmailMutex the lock is to avoid duplicate check email, maybe multiple goroutine check email at the same time --- pkg/channels/email/email.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/channels/email/email.go b/pkg/channels/email/email.go index c403c85df..60801ca32 100644 --- a/pkg/channels/email/email.go +++ b/pkg/channels/email/email.go @@ -49,9 +49,13 @@ const ( type EmailChannel struct { *channels.BaseChannel - config config.EmailConfig - imapClient *client.Client - lastUID uint32 + config config.EmailConfig + imapClient *client.Client + lastUID uint32 + // checkEmailMutex + // maybe multiple goroutine check email at the same time, use mutex to avoid duplicate check + checkEmailMutex sync.Mutex + mu sync.Mutex cancel context.CancelFunc checkTicker *time.Ticker @@ -580,6 +584,9 @@ func (c *EmailChannel) runIdleLoop(ctx context.Context, pollInterval time.Durati } func (c *EmailChannel) CheckNewEmails(ctx context.Context) { + // the lock is to avoid duplicate check email, maybe multiple goroutine check email at the same time + c.checkEmailMutex.Lock() + defer c.checkEmailMutex.Unlock() for { if err := ctx.Err(); err != nil { return