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

Abierto Apto para principiantes
#8,726 3 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@CJstate ya está trabajando en esto.

Desde el 1/11/2026.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
75/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python, redis
Área
databases

Línea de trabajo

El error está en aws_lambda_powertools/utilities/idempotency/persistence/redis.py: _orphan_lock_timeout se establece en CachePersistenceLayer.__init__ antes de que expires_after_seconds se configure. Mueve ese cálculo a _acquire_lock usando self.expires_after_seconds en el momento de la llamada, y añade una prueba con cliente falso que afirme que el ex pasado a set coincide con la expiración configurada.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Python
Estrellas
3.3k
Forks
511
Merge medio
3 d 8 h
PR fusionados (30 d)
92

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de aws-powertools/powertools-lambda-python

Todos los issues de aws-powertools/powertools-lambda-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.