fix(fetcher/idle): make mailbox-update channel send non-blocking#1270
Open
mvanhorn wants to merge 1 commit into
Open
fix(fetcher/idle): make mailbox-update channel send non-blocking#1270mvanhorn wants to merge 1 commit into
mvanhorn wants to merge 1 commit into
Conversation
The Mailbox callback runs on the IMAP socket-reader goroutine. The prior synchronous send on the 32-buffered mailboxUpdates channel blocked the socket reader whenever the channel filled up, and if the consuming select happened to be blocked (e.g. racing with stop-channel close ordering) IDLE quietly hung until the connection timed out. Switch to a non-blocking send with a default branch so the callback never blocks. Dropping an older count is safe: the consumer only acts on the latest value via prevExists tracking, so any dropped update is superseded by the next one that lands. Closes floatpane#1124
floatpanebot
requested changes
May 11, 2026
Member
floatpanebot
left a comment
There was a problem hiding this comment.
Hi @mvanhorn! Please fix the following issues with your PR:
- Title: Does not follow conventional commits (e.g.,
feat: added something,fix(core): resolved crash). - Title: Is too long (64 characters). The PR title must be strictly under 40 characters.
Member
|
scope should not contain |
floatpanebot
requested changes
May 11, 2026
Member
floatpanebot
left a comment
There was a problem hiding this comment.
Hi @floatpanebot! Please fix the following issues with your PR:
- Title: Does not follow conventional commits (e.g.,
feat: added something,fix(core): resolved crash). - Title: Is too long (64 characters). The PR title must be strictly under 40 characters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
fetcher/idle.go-- theMailboxcallback inidleOncenow uses a non-blocking send on themailboxUpdateschannel viaselect { case mailboxUpdates <- *data.NumMessages: default: }. The early-return fordata.NumMessages == nilis hoisted to keep the select body small.Closes #1124
Why?
The callback runs on the IMAP socket-reader goroutine. The prior synchronous send blocks the callback whenever the 32-buffered channel is full, which stalls the socket reader itself. If the consuming select happens to be blocked (the stop-channel close race the issue describes), IDLE quietly hangs until the connection times out.
mailboxUpdatesis a status-only channel: the consumer at line 191 only cares whether the latest count exceedsprevExists. Any value older than the most recent is already obsolete, so dropping a stale update on a full channel is harmless - the next callback fires with the current count and delivers it. The synchronous send traded nothing for the guaranteed deadlock in the failure mode the issue describes; the non-blocking send keeps the socket reader alive at the cost of a stale buffered value that would have been overwritten anyway.go build ./fetcher/...clean,go vet ./fetcher/...clean,go test ./fetcher/...->ok github.com/floatpane/matcha/fetcher 0.468s. Eleven lines inside one closure; no public API change, no new dependency.