-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Catch mail exceptions and still remove sent emails from queue #574
Conversation
Verified on an instance that faced this issue 👍 |
I touched a similar bit there #569 |
Ah good work, sorry! I could merge these two tomorrow. But then I was thinking, is it right for the activity app to be doing the validation of emails here? With this it will catch and log the exception if the email is invalid? |
where to catch it then ? |
Maybe |
@tomneedham sounds good. We still need to make sure the apps like activity catch the exception and properly skip instead of failing horribly |
That's what I implemented here :) |
try { | ||
$this->mqHandler->sendEmailToUser($uid, $user['email'], $language, $timezone, $sendTime); | ||
$sentMailForUsers[] = $uid; | ||
} catch (\Exception $e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't that too tight an exception ? we likely only want to catch and skip validation exceptions.
If the mail server (SMTP) isn't available, we should directly abort instead of continuing the queue.
This was a bit the idea in my PR, except that instead of inventing a new exception in the mailer I just did the validation directly in activity. Probably not the best idea. Should we invent a new exception in our mailer code then ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well we have to catch everything here so that we can later delete the items that were sent. I was seeing an error where the SMTP server was going away which was uncaught. Maybe we can catch here, exit the loop, run a cleanup method then rethrow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good
80bdf6e
to
e2c3ae4
Compare
Ok, I catch any exception that comes out of the mailer, run the cleanup, then throw it again which is caught by the background job handler and logged appropriately. This means:
|
JS fail unrelated, merging. @tomneedham please backport. I'll have to figure a way to rebase my PRs to be integrated with your fresh changes |
Sorry!!! :) |
@tomneedham if this is important and needed for stable9.1 or so, please backport. Else remove the lable. |
We have an issue where an exception is triggered when too many mails are sent in one mail connection. This is uncaught which causes the background job to fail. This means the items that are sent at the beginning of this loop dont get removed from the queue and are sent multiple times.
This PR logs the exception and maintains a list of successful email attempts to cleanup after the emails have been attempted.