feat: add checkEmailMutex the lock is to avoid duplicate check email, maybe multiple goroutine check email at the same time

This commit is contained in:
zhouliang 2026-02-26 02:35:28 +08:00
parent 611334b3e2
commit 5d1b64c3a4

View file

@ -52,6 +52,10 @@ type EmailChannel struct {
config config.EmailConfig config config.EmailConfig
imapClient *client.Client imapClient *client.Client
lastUID uint32 lastUID uint32
// checkEmailMutex
// maybe multiple goroutine check email at the same time, use mutex to avoid duplicate check
checkEmailMutex sync.Mutex
mu sync.Mutex mu sync.Mutex
cancel context.CancelFunc cancel context.CancelFunc
checkTicker *time.Ticker checkTicker *time.Ticker
@ -580,6 +584,9 @@ func (c *EmailChannel) runIdleLoop(ctx context.Context, pollInterval time.Durati
} }
func (c *EmailChannel) CheckNewEmails(ctx context.Context) { 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 { for {
if err := ctx.Err(); err != nil { if err := ctx.Err(); err != nil {
return return