mail intake: stop deadlocking on batches larger than the FETCH buffer #1

Merged
founder merged 1 commit from mail-intake-fetch-deadlock into main 2026-08-16 05:22:09 +00:00
Owner

pollMailbox issued STORE \Seen per message from inside the streaming FETCH loop; go-imap v1's single reader can't deliver that STORE's response until all FETCH results are pushed into the 20-slot channel — any batch > 20 deadlocked until timeout 5m. With billing's 336-message backlog every run wedged and no identity has received mail steers for 12+ hours. Fix: single STORE after the FETCH completes; regression test with go-imap's memory server (25 msgs) hangs on old code, passes now.

🤖 Generated with Claude Code

`pollMailbox` issued `STORE \Seen` per message from inside the streaming FETCH loop; go-imap v1's single reader can't deliver that STORE's response until all FETCH results are pushed into the 20-slot channel — any batch > 20 deadlocked until `timeout 5m`. With billing's 336-message backlog every run wedged and **no identity has received mail steers for 12+ hours**. Fix: single STORE after the FETCH completes; regression test with go-imap's memory server (25 msgs) hangs on old code, passes now. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
pollMailbox streamed FETCH results through a 20-slot channel and issued a
STORE \Seen for each message from inside that loop. go-imap's single reader
goroutine cannot deliver the STORE's tagged response until every FETCH
result has been pushed into the channel, and the loop was blocked waiting
for that response instead of draining the channel -- so any batch larger
than 20 messages wedged the intake until systemd's 5-minute timeout killed
it, without marking anything seen. Once the billing mailbox accumulated a
336-message backlog (the Forward Email verification outage), every run
deadlocked on the same newest-50 batch and no identity received mail
steers for over twelve hours; the routing smoke's mail leg has been red
since.

Collect the processed sequence numbers and mark them \Seen with one STORE
after the FETCH completes, drain the channel on enqueue errors instead of
abandoning the FETCH goroutine, and add a regression test that runs
pollMailbox against go-imap's in-memory server with 25 messages -- it hangs
on the old code and passes now.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
key-store/dispatch!1
No description provided.