From dadf3d72e370dd7ec04e6d59512b7a79a43cc3c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 20 May 2026 15:36:54 +0200 Subject: [PATCH] Fix infinite retry loop on signing errors in worker Catch SigningError separately (logged at ERROR level) and fix the ack/nack logic so failed messages are requeued once then discarded, instead of being requeued indefinitely or lost. Remove the bare `raise e` that crashed the worker after each error. Co-Authored-By: Claude Sonnet 4.6 --- pythonProject/worker.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pythonProject/worker.py b/pythonProject/worker.py index eff7209..b4db483 100644 --- a/pythonProject/worker.py +++ b/pythonProject/worker.py @@ -5,6 +5,7 @@ import os import pika import sign +from pyhanko.sign.general import SigningError LOG_FORMAT = ('%(levelname) -10s %(asctime)s %(name) -30s %(funcName) ' '-35s %(lineno) -5d: %(message)s') @@ -67,16 +68,22 @@ def on_message(channel, method_frame, header_frame, body): LOGGER.debug("signed file resend to amqp") channel.basic_ack(delivery_tag=method_frame.delivery_tag) - except Exception as e: - LOGGER.warning(f"error encountered while signing: {e}") + except SigningError as e: + LOGGER.error(f"signing error for signatureId {body_content['signatureId']}: {e}", exc_info=True) if method_frame.redelivered: - LOGGER.warning( - f"stopping handling this message, because the message is already redelivered, signatureId: {body_content['signatureId']}") - channel.basic_reject(delivery_tag=method_frame.delivery_tag, requeue=True) + LOGGER.error(f"message already redelivered, discarding signatureId: {body_content['signatureId']}") + channel.basic_reject(delivery_tag=method_frame.delivery_tag, requeue=False) else: - LOGGER.warning(f"first try failed, signatureId: {body_content['signatureId']}") - channel.basic_ack(delivery_tag=method_frame.delivery_tag) - raise e + LOGGER.warning(f"first try failed, requeueing for one retry, signatureId: {body_content['signatureId']}") + channel.basic_nack(delivery_tag=method_frame.delivery_tag, requeue=True) + except Exception as e: + LOGGER.warning(f"error encountered while signing, signatureId: {body_content['signatureId']}: {e}", exc_info=True) + if method_frame.redelivered: + LOGGER.warning(f"message already redelivered, discarding signatureId: {body_content['signatureId']}") + channel.basic_reject(delivery_tag=method_frame.delivery_tag, requeue=False) + else: + LOGGER.warning(f"first try failed, requeueing for one retry, signatureId: {body_content['signatureId']}") + channel.basic_nack(delivery_tag=method_frame.delivery_tag, requeue=True) if __name__ == '__main__':