From 1543e112710fa67bc4fd4cef1bf8bcc692bc0c4b Mon Sep 17 00:00:00 2001 From: Simon Thulbourn Date: Wed, 17 Jul 2024 09:56:14 +0000 Subject: [PATCH 1/3] fix(idempotency): fix timeout bug from #4759 --- aws_lambda_powertools/utilities/idempotency/persistence/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws_lambda_powertools/utilities/idempotency/persistence/base.py b/aws_lambda_powertools/utilities/idempotency/persistence/base.py index 95736634ca6..d303d447a6f 100644 --- a/aws_lambda_powertools/utilities/idempotency/persistence/base.py +++ b/aws_lambda_powertools/utilities/idempotency/persistence/base.py @@ -301,7 +301,7 @@ def save_inprogress(self, data: Dict[str, Any], remaining_time_in_millis: Option payload_hash=self._get_hashed_payload(data=data), ) - if remaining_time_in_millis: + if remaining_time_in_millis is not None: now = datetime.datetime.now() period = datetime.timedelta(milliseconds=remaining_time_in_millis) timestamp = (now + period).timestamp() From f3b049bbf0e8410f41aa384efbad48086c766a24 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Fri, 19 Jul 2024 15:11:57 +0100 Subject: [PATCH 2/3] Adding comment --- .../utilities/idempotency/persistence/base.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aws_lambda_powertools/utilities/idempotency/persistence/base.py b/aws_lambda_powertools/utilities/idempotency/persistence/base.py index d303d447a6f..3ff09bbdb2f 100644 --- a/aws_lambda_powertools/utilities/idempotency/persistence/base.py +++ b/aws_lambda_powertools/utilities/idempotency/persistence/base.py @@ -301,6 +301,10 @@ def save_inprogress(self, data: Dict[str, Any], remaining_time_in_millis: Option payload_hash=self._get_hashed_payload(data=data), ) + # When Lambda kills the container after timeout, the remaining_time_in_millis is 0, which is considered False. + # Therefore, we need to check if remaining_time_in_millis is not None (>=0) to handle this case. + # See: + if remaining_time_in_millis is not None: now = datetime.datetime.now() period = datetime.timedelta(milliseconds=remaining_time_in_millis) From ff85d0c50b9f1648da5c0f80adcce08bf3884c0d Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Fri, 19 Jul 2024 15:12:22 +0100 Subject: [PATCH 3/3] Adding comment --- .../utilities/idempotency/persistence/base.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/aws_lambda_powertools/utilities/idempotency/persistence/base.py b/aws_lambda_powertools/utilities/idempotency/persistence/base.py index 3ff09bbdb2f..8f41337cf5f 100644 --- a/aws_lambda_powertools/utilities/idempotency/persistence/base.py +++ b/aws_lambda_powertools/utilities/idempotency/persistence/base.py @@ -303,8 +303,7 @@ def save_inprogress(self, data: Dict[str, Any], remaining_time_in_millis: Option # When Lambda kills the container after timeout, the remaining_time_in_millis is 0, which is considered False. # Therefore, we need to check if remaining_time_in_millis is not None (>=0) to handle this case. - # See: - + # See: https://github.com/aws-powertools/powertools-lambda-python/issues/4759 if remaining_time_in_millis is not None: now = datetime.datetime.now() period = datetime.timedelta(milliseconds=remaining_time_in_millis)