Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Mail Queue Infinite Loop on Exception

Hello fellow programmers, I wish everyone a good morning.

The Situation

Laravel is great. Laravel Mail queues and the beanstalkd integration is great. It took me almost no time to get everything working. The sun is shining and its not raining. Its awesome.

Except when an exception is thrown while sending an email. Then thise mail is processed again and again and again and the exception is also thrown again and again and again.

Infinite loop.

I think I wouldnt even notice this if I wouldn't have seeded the database with invalid data. Validation usually would have taken care of that, that emails like 361FlorindaMatthä[email protected] dont end up with the folowing exception:

[Swift_RfcComplianceException]
Address in mailbox given [361FlorindaMatthä[email protected]] does not comply with RFC 2822, 3.6.2.

But what validation wouldnt have taken care for is for example, when my mandrill account reaches its limits or my server looses internet connection, whatever. An Exception sends it into an infinite loop.

In the world where the sun is shining and everything is great the job has to be marked as buried or suspended and the next email should be processed. An infinite loop with an invalid email address is not great.

Basicly your application doesnt send out any emails anymore. This guy has roughly the same issue.

How can I fix this? Has anyone else encountered this Error?

Any Help is much appreciated.

like image 430
Mythli Avatar asked May 04 '15 08:05

Mythli


1 Answers

You just need to travel Laravel how many times to try a specific job, before deciding it has failed:

php artisan queue:daemon --tries=3

This way, it will stop processing that specific job after 3 tries.

like image 53
Laurence Avatar answered Oct 05 '22 18:10

Laurence