From 77a65423742974039099450e5e0cdf57e9f7ad5d Mon Sep 17 00:00:00 2001 From: Luke Plant Date: Thu, 28 Dec 2023 20:03:26 +0000 Subject: [PATCH] Fix for crasher in runmailer_pg --- CHANGES.rst | 5 +++++ src/mailer/postgres.py | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 259d167..2fc47ff 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,11 @@ Change log ========== +2.3.1 - unreleased +------------------ + +* Fixed rare crasher in runmailer_pg when notifications list is empty. + 2.3 - 2023-09-25 ---------------- diff --git a/src/mailer/postgres.py b/src/mailer/postgres.py index 0af2875..983bc57 100644 --- a/src/mailer/postgres.py +++ b/src/mailer/postgres.py @@ -60,7 +60,14 @@ def postgres_send_loop(): pass else: conn.poll() - last = conn.notifies.pop() + try: + last = conn.notifies.pop() + except IndexError: + # Not entirely sure how this happens, but it could only happen + # if `notifies` is empty, because there are no more notifications + # to process. + continue + # We don't care about payload or how many NOTIFY there were, # we'll just run once, so drop the rest: to_drop = conn.notifies