fix(auth): use asyncio.to_thread for credential resolution in signing hook#270
Open
nix-tkobayashi wants to merge 3 commits into
Open
fix(auth): use asyncio.to_thread for credential resolution in signing hook#270nix-tkobayashi wants to merge 3 commits into
nix-tkobayashi wants to merge 3 commits into
Conversation
… hook `_sign_request_hook` is an async httpx event hook, but it calls `session_holder.session.get_credentials()` and `session_holder.refresh_if_needed()` synchronously. For profiles that use assumed IAM roles (chained credentials), `get_credentials()` triggers a blocking STS `AssumeRole` call that stalls the event loop and causes connection timeouts (~60 s). Add `SessionHolder.async_get_credentials()` and `SessionHolder.async_refresh_if_needed()` which delegate to `asyncio.to_thread`, keeping the event loop responsive. Update `_sign_request_hook` to call the async variants. Fixes aws#176 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2 tasks
Address review feedback: - Clarify that get_credentials() is the primary blocking path; async_refresh_if_needed() is a defensive measure - Replace timeout-based non-blocking test with ticker coroutine that proves the event loop stays responsive during credential resolution Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Changes
_sign_request_hookis an async httpx event hook, but it callssession_holder.session.get_credentials()andsession_holder.refresh_if_needed()synchronously. For AWS profiles that use assumed IAM roles (chained credentials),get_credentials()triggers a blocking STSAssumeRolecall that stalls the asyncio event loop, causing ~60 second connection timeouts.This PR:
SessionHolder.async_get_credentials()andSessionHolder.async_refresh_if_needed()which delegate blocking botocore calls toasyncio.to_thread()_sign_request_hookto use the async variantsUser experience
Before: Using an AWS profile backed by an assumed IAM role (chained credentials) causes the MCP proxy connection to time out after ~60 seconds:
After: The connection succeeds normally. The STS
AssumeRolecall runs in a worker thread, keeping the event loop responsive.Checklist
Is this a breaking change? (Y/N)
Please add details about how this change was tested.
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Fixes #176