Skip to content

feat(idempotency): enhance thread safety with AsyncLocal context and thread-safe configuration#1084

Merged
hjgraca merged 11 commits intodevelopfrom
feat/idempotency-thread-safety
Dec 16, 2025
Merged

feat(idempotency): enhance thread safety with AsyncLocal context and thread-safe configuration#1084
hjgraca merged 11 commits intodevelopfrom
feat/idempotency-thread-safety

Conversation

@hjgraca
Copy link
Contributor

@hjgraca hjgraca commented Dec 16, 2025

Please provide the issue number

Issue number: #1083

Summary

Changes

This pull request introduces significant improvements to thread safety and concurrency handling in the idempotency library, ensuring correct behavior when AWS Lambda runs with multiple concurrent invocations. The main changes include using thread-local and AsyncLocal storage to isolate per-invocation state, making configuration methods thread-safe and idempotent.. These changes help prevent cross-thread data leakage and race conditions.

Idempotency library improvements:

  • Thread-safe Lambda context storage: Replaces a static property with AsyncLocal<ILambdaContext> in Idempotency to ensure each Lambda invocation has its own isolated context, preventing context leaks between concurrent executions. (Idempotency.cs) [1] [2] [3]
  • Thread-safe configuration in persistence store: Adds locking and a double-check pattern to BasePersistenceStore.Configure methods, using a lock and a volatile flag to make configuration idempotent and safe for concurrent calls. (BasePersistenceStore.cs) [1] [2] [3]

User experience

Please share what the user experience looks like before and after this change

Checklist

Please leave checklist items unchecked if they do not apply to your change.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@boring-cyborg boring-cyborg bot added area/idempotency area/metrics Core metrics utility area/tracing Core tracing utility tests labels Dec 16, 2025
@pull-request-size pull-request-size bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Dec 16, 2025
@github-actions github-actions bot added the feature New features or minor changes label Dec 16, 2025
@codecov
Copy link

codecov bot commented Dec 16, 2025

Codecov Report

❌ Patch coverage is 81.13208% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.39%. Comparing base (b0bd80e) to head (e197d1f).
⚠️ Report is 6 commits behind head on develop.

Files with missing lines Patch % Lines
...ls.Idempotency/Persistence/BasePersistenceStore.cs 81.63% 6 Missing and 3 partials ⚠️
...c/AWS.Lambda.Powertools.Idempotency/Idempotency.cs 75.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1084      +/-   ##
===========================================
+ Coverage    78.36%   78.39%   +0.02%     
===========================================
  Files          298      298              
  Lines        12126    12157      +31     
  Branches      1456     1464       +8     
===========================================
+ Hits          9503     9530      +27     
- Misses        2158     2159       +1     
- Partials       465      468       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud
Copy link

@hjgraca hjgraca merged commit 002d909 into develop Dec 16, 2025
10 checks passed
@hjgraca hjgraca deleted the feat/idempotency-thread-safety branch December 16, 2025 12:30
@hjgraca hjgraca linked an issue Dec 17, 2025 that may be closed by this pull request
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/idempotency area/metrics Core metrics utility area/tracing Core tracing utility feature New features or minor changes size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Idempotency LMI support

2 participants