fix: mailbox channel send non-blocking (#1270)

Matt Van Horn created

Change summary

fetcher/idle.go | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

Detailed changes

fetcher/idle.go 🔗

@@ -158,8 +158,17 @@ func (a *accountIdle) idleOnce() error {
 	mailboxUpdates := make(chan uint32, 32)
 	c, err := connectWithHandler(a.account, &imapclient.UnilateralDataHandler{
 		Mailbox: func(data *imapclient.UnilateralDataMailbox) {
-			if data.NumMessages != nil {
-				mailboxUpdates <- *data.NumMessages
+			if data.NumMessages == nil {
+				return
+			}
+			// Non-blocking send: the callback runs on the IMAP socket-reader
+			// goroutine, so a synchronous send would stall the socket if the
+			// channel is full. The consumer only acts on the latest count
+			// (see prevExists tracking below), so dropping a stale update is
+			// safe — the next update will deliver the current count.
+			select {
+			case mailboxUpdates <- *data.NumMessages:
+			default:
 			}
 		},
 	})