Skip to content

Stop the email loop when error email delivery fails - #104

Merged
fractaledmind merged 1 commit into
mainfrom
fix/email-delivery-failure-loop
Oct 13, 2026
Merged

fractaledmind merged 1 commit into
mainfrom
fix/email-delivery-failure-loop

Conversation

@fractaledmind

Copy link
Copy Markdown
Owner

Fixes #89.

When the error email fails to deliver (bad SMTP credentials, a host that's down), the failed delivery job's exception is reported through Rails.error. That creates an occurrence, the occurrence enqueues another error email, that email fails too, and the cycle never ends.

ErrorMailer now handles its own failures with rescue_from StandardError. That covers rendering errors as well as delivery errors, because ActionMailer routes delivery through handle_exceptions. It reports the exception inside SolidErrors.without_emails, a block during which send_emails? is false for the current thread or fiber. So:

  • the failure still appears in the dashboard and reaches every other Rails.error subscriber, but nothing emails about it;
  • emails resume for the next error, because the flag is restored when the block exits.

Trade-off: the delivery job no longer re-raises, so ActiveJob won't retry a transient SMTP failure for that one email. Retrying is what kept the loop going, and the failure stays visible in the dashboard.

Tests use a delivery method that always fails. Without the fix, the delivery error escapes the job and both new tests error.

🤖 Generated with Claude Code

A delivery failure was reported like any other error, which created an
occurrence, which sent another email, which failed again. The mailer now
reports its own failures with emails switched off for that report. Fixes #89.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@fractaledmind
fractaledmind merged commit 8399566 into main Oct 13, 2026
17 checks passed
@fractaledmind
fractaledmind deleted the fix/email-delivery-failure-loop branch October 13, 2026 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infinite loop when email delivery fails

1 participant