Skip to content

chore: Enhanced error handling and timeout management in the request methods - #18327

Draft
agrawalradhika-cell wants to merge 3 commits into
mainfrom
agrawalradhika-cell-patch-1
Draft

chore: Enhanced error handling and timeout management in the request methods#18327
agrawalradhika-cell wants to merge 3 commits into
mainfrom
agrawalradhika-cell-patch-1

Conversation

@agrawalradhika-cell

Copy link
Copy Markdown
Contributor

… methods.

Enhanced error handling and timeout management in the request methods.

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

…methods.

 Enhanced error handling and timeout management in the request methods.
@agrawalradhika-cell
agrawalradhika-cell requested review from a team as code owners September 9, 2026 23:58

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the asynchronous authorized session transport to enhance mutual TLS (mTLS) support, certificate rotation, and error handling. Key improvements include a non-blocking configure_mtls_channel flow and better cleanup of resources during request failures. The review feedback highlights three critical issues: potential unhandled CancelledError when checking the mTLS initialization task's exception status, a logical bug in the duplicate credential refresh check condition that can trigger redundant refreshes, and blocking the async event loop with the CPU-bound certificate context creation instead of running it in an executor.

Comment thread packages/google-auth/google/auth/aio/transport/sessions.py
Comment thread packages/google-auth/google/auth/aio/transport/sessions.py Outdated
Comment on lines +223 to +227
ssl_context = (
mtls.make_client_cert_ssl_context(
cert_bytes, key_bytes
)
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

mtls.make_client_cert_ssl_context is a CPU-bound operation that parses certificates and private keys. Running it directly in the async event loop can block the loop and degrade performance of concurrent tasks. It should be run in an executor using await mtls._run_in_executor as was done in the previous implementation.

Suggested change
ssl_context = (
mtls.make_client_cert_ssl_context(
cert_bytes, key_bytes
)
)
ssl_context = await mtls._run_in_executor(
mtls.make_client_cert_ssl_context,
cert_bytes,
key_bytes,
)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@agrawalradhika-cell
agrawalradhika-cell marked this pull request as draft September 10, 2026 00:11
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant