Repository navigation
Commit a39e101
fix(idempotency): Redis persistence layer reclaims live in-progress records as orphans, allowing concurrent double-execution (#8387)
* fix(idempotency): Redis persistence layer reclaims live in-progress records as orphans, allowing concurrent double-execution
RedisCachePersistenceLayer._put_in_progress_record() only guarded against a
competing invocation when the existing record's in_progress_expiry_timestamp
was set AND still in the future. When that field is None -- which is the
normal case for idempotent_function, since it never calls
config.register_lambda_context(), unlike the idempotent() handler decorator --
the guard was skipped entirely and a genuinely still-running invocation's
record fell through to the "orphan record" branch, which unconditionally
overwrites the record with no NX guard. A second concurrent invocation with
the same idempotency key would then proceed to execute the underlying
function too, defeating idempotency (e.g. double-charging a customer).
This is exactly what persistence/base.py's own warning at that call site
flags ("Couldn't determine the remaining time left. Did you call
register_lambda_context on IdempotencyConfig?") -- it warns, but nothing
downstream actually failed closed on it.
The DynamoDB persistence layer does not have this gap: its conditional
expression requires attribute_exists(#in_progress_expiry) before allowing an
expired-in-progress reclaim, so a missing attribute correctly blocks the
competing writer instead of granting a reclaim.
Fix: when status is INPROGRESS and in_progress_expiry_timestamp is None,
treat the record as still in progress (fail closed) instead of falling
through to the orphan-reclaim path, mirroring the DynamoDB layer's behavior.
* test(idempotency): cover concurrent cache execution
---------
Co-authored-by: Leandro <lcdama@amazon.pt>1 parent 78fdd32 commit a39e101
2 files changed
Lines changed: 85 additions & 4 deletions
File tree
- aws_lambda_powertools/utilities/idempotency/persistence
- tests/functional/idempotency/_redis
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
425 | 425 | | |
426 | 426 | | |
427 | 427 | | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
432 | 434 | | |
433 | 435 | | |
434 | 436 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
198 | 200 | | |
199 | 201 | | |
200 | 202 | | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
201 | 213 | | |
202 | 214 | | |
203 | 215 | | |
| |||
303 | 315 | | |
304 | 316 | | |
305 | 317 | | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
306 | 385 | | |
307 | 386 | | |
308 | 387 | | |
| |||
0 commit comments