Bug: Redis orphan lock timeout ignores expires_after_seconds and is always 10 seconds
[!WARNING] For contributors, human or agent. Comment here to claim this issue and wait for the assignment before opening a PR; if two PRs show up, the assignee's stays. AI-assisted work is welcome, say so in the PR and tell us how you verified it: run the tests yourself and paste what you saw, do not describe runs you did not do. Read AGENTS.md first, it has the commands and the rules the CI enforces. This goes into 3.41.0.
Expected Behaviour
The Redis orphan lock lives at most as long as the record: _orphan_lock_timeout = min(10, expires_after_seconds) uses the configured expires_after_seconds.
Current Behaviour
The value is computed in CachePersistenceLayer.__init__, before configure() has set expires_after_seconds, so it always sees the default 3600 and the timeout is always 10. With expires_after_seconds=2 the lock outlives the record by 8 seconds, and a request in that window that finds an orphaned record fails with IdempotencyInconsistentStateError instead of taking over.
Code snippet
from aws_lambda_powertools.utilities.idempotency import IdempotencyConfig
from aws_lambda_powertools.utilities.idempotency.persistence.redis import CachePersistenceLayer
layer = CachePersistenceLayer(client=redis_client)
layer.configure(IdempotencyConfig(expires_after_seconds=2), "fn")
layer._orphan_lock_timeout # 10, expected 2
For a public-API test, use a short expires_after_seconds, let a record go orphan, and assert the next call runs instead of raising.
Possible Solution
Compute the timeout where it is used, in _acquire_lock in aws_lambda_powertools/utilities/idempotency/persistence/redis.py, from self.expires_after_seconds at call time. Add a test with a fake Redis client asserting the ex value passed to set follows the configured expiry.
Item 9 of the Idempotency audit in #8603. No AWS resources needed, the Redis tests use a fake client.
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.13
Packaging format used
PyPi
Debugging logs
No response
[!note] For those interested in contributing, please leave a comment below so that we can assign the issue to you and make sure we don't duplicate efforts. If you have any further questions, please don't hesitate to ask below or on our Discord server.
I'd like to take this one.
Plan: compute the lock timeout in _acquire_lock from self.expires_after_seconds at call time (capped at 10s), instead of caching it in __init__ before configure() runs. I'll add a regression test that drives the public idempotent decorator with a fake Redis client, turns the stored record into an orphan, and asserts the ex passed to SET for the <key>:lock call is min(10, expires_after_seconds) (with a second case checking the 10s cap).
I'll wait for the assignment before opening the PR. AI-assisted, and I'll paste the actual test output in the PR.
@CJstate it's yours, assigning you now. Go ahead with the PR, and say in the description how you ran the tests.
I saw this issue is still open and would love to work on it. my approach would be similar to CJstate's approach. I traced it to CachePersistenceLayer.init computing _orphan_lock_timeout = min(10, self.expires_after_seconds) before configure() has applied IdempotencyConfig, so it always sees the 3600s base default and the lock is always 10s. I would compute the timeout inside _acquire_lock at acquisition time, and add a functional test through the public API that checks the lock TTL for expires_after_seconds below, at and above 10.
[!warning] This issue is now closed. Please be mindful that future comments are hard for our team to see. If you need more assistance, please either reopen the issue, or open a new issue referencing this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
This is now released under 3.41.0 version!