From caa61a463eb6871417f222aca5ff6057e29dfa9a Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 21 Apr 2021 11:33:15 +0200 Subject: [PATCH] Mail: Retry if pulling attachments failed --- src/pretix/base/services/mail.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/pretix/base/services/mail.py b/src/pretix/base/services/mail.py index 70dc895a1..7f5313376 100644 --- a/src/pretix/base/services/mail.py +++ b/src/pretix/base/services/mail.py @@ -355,9 +355,20 @@ def mail_send_task(self, *args, to: List[str], subject: str, body: str, html: st args = [] attach_size = 0 for name, ct in get_tickets_for_order(order, base_position=position): - content = ct.file.read() - args.append((name, content, ct.type)) - attach_size += len(content) + try: + content = ct.file.read() + args.append((name, content, ct.type)) + attach_size += len(content) + except: + # This sometimes fails e.g. with FileNotFoundError. We haven't been able to figure out + # why (probably some race condition with ticket cache invalidation?), so retry later. + try: + self.retry(max_retries=5, countdown=60) + except MaxRetriesExceededError: + # Well then, something is really wrong, let's send it without attachment before we + # don't sent at all + logger.exception('Could not attach invoice to email') + pass if attach_size < 4 * 1024 * 1024: # Do not attach more than 4MB, it will bounce way to often.