Bug: Redis orphan lock timeout ignores expires_after_seconds and is always 10 seconds

オープン 初心者向け
#8,726 コメント 3 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@CJstate がすでに取り組んでいます。

2026年11月1日 から。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
75/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python, redis
領域
databases

調査の方向性

バグは aws_lambda_powertools/utilities/idempotency/persistence/redis.py: _orphan_lock_timeout は CachePersistenceLayer.__init__ で expires_after_seconds が設定される前に設定されます。その計算を _acquire_lock に移動し、呼び出し時に self.expires_after_seconds を使用して、ex が set に渡されるものが設定された有効期限と一致することをアサートする fake-client テストを追加してください。

索引モデルが issue の本文から書いたものです。

説明

bug good first issue help wanted idempotency

[!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

主要言語
Python
スター
3.3k
フォーク
511
平均マージ
3日 8時間
マージ済み PR(30日)
92

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

aws-powertools/powertools-lambda-python のほかの issue

aws-powertools/powertools-lambda-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。