Skip to content

Commit bb94316

Browse files
karlitschekclaude
andcommitted
fix(mail): stop CLI email loops spinning on users that fail to load
When looking up a user threw, sendEmails() skipped the user without removing their queue entries. Since getAffectedUsers() always returns the users with the oldest pending items first, and both EmailNotification (cron) and the send-emails command loop while a full batch was reported, a full batch of users with a broken user backend made those loops spin on the same batch forever, retrying and logging endlessly within one run. Report the number of users actually dealt with instead of the number of affected users, so a batch containing failed lookups ends the loop and the skipped users are retried on the next run. This also matches the documented return value. Entries of users that fail to load are still kept for retry: a lookup for a deleted user returns null (handled via the empty-email path), a throw indicates a temporarily broken backend and pending emails should not be discarded because of it. Signed-off-by: Frank Karlitschek <karlitschek@users.noreply.github.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 6ae4d1f commit bb94316

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

lib/MailQueueHandler.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ public function sendEmails(int $limit, int $sendTime, bool $forceSending = false
136136
// Delete all entries we dealt with
137137
$this->deleteSentItems($deleteItemsForUsers, $sendTime);
138138

139-
return count($affectedUsers);
139+
// Only count the users that were actually dealt with, so a batch of
140+
// users whose lookup failed does not keep the CLI loops of the
141+
// callers spinning on the same batch forever.
142+
return count($deleteItemsForUsers);
140143
}
141144

142145
/**

0 commit comments

Comments
 (0)