Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Make ssl_channel_credentials async#378

Merged
mangelajo merged 3 commits intomainfrom
keepalive
Mar 26, 2025
Merged

Make ssl_channel_credentials async#378
mangelajo merged 3 commits intomainfrom
keepalive

Conversation

@NickCao
Copy link
Copy Markdown
Collaborator

@NickCao NickCao commented Mar 26, 2025

Summary by CodeRabbit

  • Refactor
    • Converted channel credential and channel factory methods to asynchronous operations.
    • Introduced a timeout mechanism to enhance error management by catching delays and reporting connection issues.
    • Updated related workflows to await asynchronous operations, ensuring smoother and more responsive communication.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 26, 2025

Walkthrough

This pull request converts the ssl_channel_credentials function from a synchronous to an asynchronous function by updating its definition and adding a timeout parameter. The implementation now uses anyio.fail_after to enforce the timeout for obtaining server certificates and re-raises timeout issues as a ConnectionError. In addition, all call sites—including those in router streams, client configuration, and exporter configuration—have been updated to await the asynchronous function, ensuring proper asynchronous handling throughout the gRPC channel and stub creation workflows.

Changes

File(s) Summary
packages/jumpstarter/jumpstarter/common/grpc.py Updated ssl_channel_credentials to an async function with a timeout parameter; integrated anyio.fail_after for timeout management and enhanced error handling by converting TimeoutError to ConnectionError.
packages/jumpstarter/jumpstarter/common/streams.py, packages/jumpstarter/jumpstarter/config/client.py, packages/jumpstarter/jumpstarter/config/exporter.py Modified calls to ssl_channel_credentials to use await, aligning with its new asynchronous signature and ensuring synchronous compatibility across components.
packages/jumpstarter/jumpstarter/exporter/exporter.py Updated instantiation of ControllerServiceStub by awaiting channel_factory() in multiple methods to accommodate its asynchronous behavior.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Client/Exporter
    participant CredFunc as ssl_channel_credentials
    participant Timeout as anyio.fail_after
    participant SSL as ssl.get_server_certificate

    Caller->>CredFunc: await ssl_channel_credentials(target, tls_config, timeout)
    CredFunc->>Timeout: enforce timeout (e.g., 5s)
    Timeout->>SSL: run_sync(ssl.get_server_certificate)
    SSL-->>Timeout: return certificate or trigger TimeoutError
    Timeout-->>CredFunc: certificate result (or error)
    CredFunc-->>Caller: return credentials or raise ConnectionError
Loading

Possibly related PRs

Poem

I'm a hopping rabbit, light on my feet,
Async code now makes my heart skip a beat.
Credentials dance with time like a playful breeze,
Awaited flows make every process a breeze.
In a world of gRPC, I joyfully play,
Leaping through code in a bright, boppy way!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dbc50d2 and 3907ba7.

📒 Files selected for processing (5)
  • packages/jumpstarter/jumpstarter/common/grpc.py (2 hunks)
  • packages/jumpstarter/jumpstarter/common/streams.py (1 hunks)
  • packages/jumpstarter/jumpstarter/config/client.py (1 hunks)
  • packages/jumpstarter/jumpstarter/config/exporter.py (1 hunks)
  • packages/jumpstarter/jumpstarter/exporter/exporter.py (4 hunks)
🧰 Additional context used
🧬 Code Definitions (4)
packages/jumpstarter/jumpstarter/common/streams.py (1)
packages/jumpstarter/jumpstarter/common/grpc.py (1)
  • ssl_channel_credentials (16-40)
packages/jumpstarter/jumpstarter/exporter/exporter.py (1)
packages/jumpstarter/jumpstarter/config/exporter.py (1)
  • channel_factory (162-167)
packages/jumpstarter/jumpstarter/common/grpc.py (1)
packages/jumpstarter/jumpstarter/common/exceptions.py (2)
  • ConfigurationError (35-38)
  • ConnectionError (29-32)
packages/jumpstarter/jumpstarter/config/client.py (1)
packages/jumpstarter/jumpstarter/common/grpc.py (1)
  • ssl_channel_credentials (16-40)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: Redirect rules - jumpstarter-docs
  • GitHub Check: Header rules - jumpstarter-docs
  • GitHub Check: Pages changed - jumpstarter-docs
  • GitHub Check: pytest-matrix (3.12)
  • GitHub Check: pytest-matrix (3.13)
  • GitHub Check: pytest-matrix (3.11)
  • GitHub Check: e2e
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-utils Dockerfile.utils)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter Dockerfile)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-dev .devfile/Containerfile)
  • GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-devspace .devfile/Containerfile.client)
🔇 Additional comments (13)
packages/jumpstarter/jumpstarter/common/streams.py (1)

37-37: Good update to handle the asynchronous credentials fetching

This change correctly adds the await keyword to properly handle the now asynchronous ssl_channel_credentials function. The function was converted to async to include proper timeout handling when obtaining server certificates.

packages/jumpstarter/jumpstarter/exporter/exporter.py (4)

32-32: Correctly updated to use await with channel_factory

The call to channel_factory now properly uses await since the function has been made asynchronous to support the new async ssl_channel_credentials.


50-50: Properly awaits asynchronous channel_factory

Good update to ensure the channel is properly instantiated in the asynchronous context.


79-79: Correctly awaits channel_factory in listen method

This change ensures that the channel is properly instantiated before being used for the listen operation.


116-116: Properly awaits asynchronous channel creation in status method

Consistent with other changes, this correctly awaits the channel_factory.

packages/jumpstarter/jumpstarter/config/exporter.py (2)

162-162: Good conversion to async function

This correctly updates the channel_factory function to be asynchronous, which is necessary since it now calls the async ssl_channel_credentials function.


164-164: Properly awaits the async ssl_channel_credentials function

This change correctly adds await to the call to ssl_channel_credentials, which has been converted to an asynchronous function to include proper timeout handling.

packages/jumpstarter/jumpstarter/config/client.py (1)

57-57: Correctly updated to await ssl_channel_credentials

This change properly awaits the now asynchronous ssl_channel_credentials function, which ensures that TLS certificate retrieval uses the new timeout mechanism.

packages/jumpstarter/jumpstarter/common/grpc.py (5)

10-11: Good addition of required async dependencies.

The imports from the anyio package are appropriate for implementing the asynchronous functionality needed for the SSL channel credentials function.


16-16: Function signature properly updated for async operation.

The function has been correctly converted to async by adding the async keyword, and the timeout parameter with a sensible default value of 5 seconds has been added.


26-27: Good implementation of timeout and async certificate retrieval.

Using fail_after to enforce a timeout and run_sync to handle the blocking SSL operation asynchronously is the right approach. This prevents the certificate retrieval from blocking the event loop while still allowing the operation to time out if it takes too long.


33-34: Proper error handling for timeout conditions.

Adding a specific handler for TimeoutError that converts it to a ConnectionError with a clear message is a good practice. This provides consistent error handling and meaningful error messages to callers.


16-40:

Details

✅ Verification successful

Verify that all callers of this function have been updated.

Since ssl_channel_credentials is now an async function, all call sites must use await when calling it.


🏁 Script executed:

#!/bin/bash
# Search for all direct calls to ssl_channel_credentials
# We should see that all calls now use await

echo "Checking for calls to ssl_channel_credentials:"
rg -p "ssl_channel_credentials\(" --no-heading | grep -v "async def ssl_channel_credentials"

echo -e "\nVerifying all calls are awaited:"
rg -p "await ssl_channel_credentials\(" --no-heading

Length of output: 1414


All call sites using ssl_channel_credentials now properly await its result.

The verification confirms that the async function is correctly awaited in:

  • packages/jumpstarter/jumpstarter/common/streams.py (line 37)
  • packages/jumpstarter/jumpstarter/config/exporter.py (line 164)
  • packages/jumpstarter/jumpstarter/config/client.py (line 57)

There are no issues left in the callers.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 26, 2025

Deploy Preview for jumpstarter-docs ready!

Name Link
🔨 Latest commit eb290db
🔍 Latest deploy log https://app.netlify.com/sites/jumpstarter-docs/deploys/67e414b5987a290008278107
😎 Deploy Preview https://deploy-preview-378--jumpstarter-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mangelajo mangelajo enabled auto-merge March 26, 2025 14:52
@mangelajo mangelajo merged commit 856239f into main Mar 26, 2025
18 checks passed
@mangelajo mangelajo added this to the 0.6.0 milestone May 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants