Skip to content

Commit 353d9ef

Browse files
authored
fix: mailbox channel send non-blocking (#1270)
1 parent b858d58 commit 353d9ef

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

fetcher/idle.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,17 @@ func (a *accountIdle) idleOnce() error {
158158
mailboxUpdates := make(chan uint32, 32)
159159
c, err := connectWithHandler(a.account, &imapclient.UnilateralDataHandler{
160160
Mailbox: func(data *imapclient.UnilateralDataMailbox) {
161-
if data.NumMessages != nil {
162-
mailboxUpdates <- *data.NumMessages
161+
if data.NumMessages == nil {
162+
return
163+
}
164+
// Non-blocking send: the callback runs on the IMAP socket-reader
165+
// goroutine, so a synchronous send would stall the socket if the
166+
// channel is full. The consumer only acts on the latest count
167+
// (see prevExists tracking below), so dropping a stale update is
168+
// safe — the next update will deliver the current count.
169+
select {
170+
case mailboxUpdates <- *data.NumMessages:
171+
default:
163172
}
164173
},
165174
})

0 commit comments

Comments
 (0)