Skip to content
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

Merged
merged 1 commit into from
Jul 4, 2017

Conversation

tomneedham
Copy link
Contributor

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.

@tomneedham
Copy link
Contributor Author

Verified on an instance that faced this issue 👍

@PVince81 PVince81 added this to the 10.0.3 milestone Jun 21, 2017
@PVince81
Copy link
Contributor

I touched a similar bit there #569

@tomneedham
Copy link
Contributor Author

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?

@PVince81
Copy link
Contributor

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 ?

@tomneedham
Copy link
Contributor Author

where to catch it then ?

Maybe $mailer->send() shoudl call the validator and emit a validation exception? which is caught by the application calling send()> Or no? Just feels weird having every use of the mailing having to run the validation method as well

@PVince81
Copy link
Contributor

@tomneedham sounds good. We still need to make sure the apps like activity catch the exception and properly skip instead of failing horribly

@tomneedham
Copy link
Contributor Author

That's what I implemented here :)

try {
$this->mqHandler->sendEmailToUser($uid, $user['email'], $language, $timezone, $sendTime);
$sentMailForUsers[] = $uid;
} catch (\Exception $e) {
Copy link
Contributor

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 ?

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good

@pmaier1 pmaier1 modified the milestones: 2.3.5 release, 10.0.3, development Jun 27, 2017
@tomneedham tomneedham force-pushed the handle-mail-exceptions branch from 80bdf6e to e2c3ae4 Compare June 29, 2017 15:05
@tomneedham
Copy link
Contributor Author

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:

  1. You get to know in the logs when something goes wrong with sending an email
  2. Successful emails get cleared so they dont spam their users

@PVince81
Copy link
Contributor

PVince81 commented Jul 4, 2017

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

@PVince81 PVince81 merged commit 6d15c2c into master Jul 4, 2017
@PVince81 PVince81 deleted the handle-mail-exceptions branch July 4, 2017 08:42
@tomneedham
Copy link
Contributor Author

I'll have to figure a way to rebase my PRs to be integrated with your fresh changes

Sorry!!! :)

@PVince81 PVince81 mentioned this pull request Jul 4, 2017
1 task
@PVince81
Copy link
Contributor

@tomneedham if this is important and needed for stable9.1 or so, please backport. Else remove the lable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants