fix(event_handler): isolate local ASGI request state - #8452
leandrodamascena merged 4 commits into
Conversation
|
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
leandrodamascena
left a comment
There was a problem hiding this comment.
I reproduced the concurrency issue and agree with the direction. I found two compatibility regressions with included Router instances; details inline.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8452 +/- ##
===========================================
+ Coverage 96.60% 96.62% +0.01%
===========================================
Files 296 296
Lines 14820 14883 +63
Branches 1257 1263 +6
===========================================
+ Hits 14317 14380 +63
Misses 366 366
Partials 137 137 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
leandrodamascena
left a comment
There was a problem hiding this comment.
Thanks for working on this @wuodar! Amazing work, approved!
|
Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience! |
|
Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience! |



Issue number: Fixes #8451
Summary
Concurrent HTTP requests to one
HttpResolverLocalASGI app can consume another request's body or lose routing context when another request completes. With Pydantic validation enabled, six distinct requests in the reproduction all return the last body.This draft isolates state on the local ASGI path. It does not introduce concurrent Lambda invocations or change
APIGatewayHttpResolver.Changes
ContextVar, includingasyncio.to_threadmiddleware and callbacks scheduled back onto the event loop.resolve()path outside ASGI requests.User experience
A local development server can handle overlapping requests without those requests overwriting the resolver's event/context. Resolution stays concurrent rather than putting a lock around every HTTP request.
Validation
developand pass with this patch.python -m pytest tests/functional/event_handler -o addopts='' -q: 863 passed, 1 skipped.mypy aws_lambda_powertools/event_handler/http_resolver.py --follow-imports=silent: passes.make prwas attempted but could not start because Poetry is not installed in the contribution environment. The checks above used a separate virtual environment; full repository CI has not been claimed as passing.Maintainer review / remaining scope
This is a draft pending issue triage and agreement on the state-isolation boundary. The patch covers state accessed through the resolver and resolver-bound dependency providers. Direct
Router.current_event/Router.contextaccess on an included upstream Router still uses legacy shared state and needs a design decision before treating this as a complete upstream solution. Existing synchronous resolver and event-handler tests remain green.Cancellation isolation does not imply that this patch cancels handler tasks already scheduled by the existing synchronous middleware bridge; it ensures their state cannot be cleared by another request.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.