fix(event_handler): isolate local ASGI request state - #8452
Open
wuodar wants to merge 1 commit into
Open
Conversation
|
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
|
|
Not all issues are linked correctly. Please link each issue to the PR either manually or using a closing keyword in the format If mentioning more than one issue, separate them with commas: i.e. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Issue number: relates to #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.