Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a timeout to graceful termination #846

Merged
merged 1 commit into from
Nov 15, 2024

Conversation

paulgb
Copy link
Member

@paulgb paulgb commented Nov 15, 2024

Important

Add a 2-second timeout for graceful server termination in ControllerServer and remove unused imports in admin.rs.

  • Behavior:
    • Add TERMINATE_TIMEOUT_DURATION constant in controller/mod.rs to set a 2-second timeout for graceful server termination.
    • Modify terminate() in ControllerServer to use tokio::time::timeout for server shutdown.
    • Log a warning if the server does not terminate gracefully within the timeout.
  • Misc:
    • Remove unused import Stream and StreamExt from admin.rs.

This description was created by Ellipsis for 02566ef. It will automatically update as commits are pushed.

Copy link

vercel bot commented Nov 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
plane ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 15, 2024 10:33pm

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Reviewed everything up to 02566ef in 29 seconds

More details
  • Looked at 61 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. plane/src/controller/mod.rs:323
  • Draft comment:
    The error handling for Ok(Err(err)) and Ok(Ok(Err(err))) is the same, which might be confusing. Consider differentiating the error messages for clarity.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The PR introduces a timeout for graceful termination, but the error handling for the server handle is not consistent. The error message for Ok(Err(err)) and Ok(Ok(Err(err))) is the same, which might be confusing.

Workflow ID: wflow_s3tuZyf577uMveoD


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Member

@rolyatmax rolyatmax left a comment

Choose a reason for hiding this comment

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

Nice! Were you able to test locally?

@paulgb
Copy link
Member Author

paulgb commented Nov 15, 2024

Nice! Were you able to test locally?

Yes, #844 was actually made as a way to test it. It works as expected locally.

Copy link
Contributor

coderabbitai bot commented Nov 15, 2024

📝 Walkthrough

Walkthrough

The pull request introduces significant changes to two files: plane/src/admin.rs and plane/src/controller/mod.rs. In admin.rs, a new command variant, PutDummyDns, has been added to the AdminCommand enum, which includes a cluster field and facilitates interactions with a proxy connection to lease a dummy DNS and set a TXT record. The run_admin_command_inner function has been updated to handle this new command, establishing a connection to the proxy, sending a CertLeaseRequest, and processing the response for lease acceptance. Existing commands remain unchanged, ensuring the overall command handling structure is preserved.

In controller/mod.rs, a new constant TERMINATE_TIMEOUT_DURATION is introduced, set to 2 seconds, which is used in the terminate method of the ControllerServer struct. This method now incorporates a timeout mechanism using tokio::time::timeout, enhancing the server's termination process. The method's control flow has been adjusted to handle timeout scenarios, and logging has been updated to reflect the new graceful shutdown process.

Possibly related PRs

  • Add backend status stream endpoint #844: Modifications to the admin.rs file, specifically adding a new command variant to the AdminCommand enum, which is directly related to the changes made in this PR with the addition of the PutDummyDns command.

Suggested reviewers

  • michaelsilver
  • rolyatmax

🪧 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 resolve resolve all the CodeRabbit review comments.
  • @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.

@paulgb paulgb merged commit 7d16a75 into main Nov 15, 2024
5 of 7 checks passed
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
plane/src/controller/mod.rs (2)

61-64: LGTM! Consider making the timeout duration configurable.

The timeout duration is well-documented and reasonable for short requests. However, consider making it configurable through ControllerConfig to allow operators to adjust based on their specific needs.

 pub struct ControllerConfig {
     pub db_url: String,
     pub bind_addr: SocketAddr,
     pub id: ControllerName,
     pub controller_url: Url,
     pub default_cluster: Option<ClusterName>,
     pub cleanup_min_age_days: Option<i32>,
     pub cleanup_batch_size: Option<i32>,
     pub forward_auth: Option<Url>,
+    pub terminate_timeout: Option<std::time::Duration>,
 }

303-303: LGTM! Consider enhancing error logging.

The timeout implementation is solid and handles all possible outcomes appropriately. However, the error logging could be more descriptive.

-                Ok(Ok(Err(err))) => {
-                    tracing::error!(?err, "Server error");
-                }
-                Ok(Err(err)) => {
-                    tracing::error!(?err, "Server error");
-                }
+                Ok(Ok(Err(err))) => {
+                    tracing::error!(?err, "Server failed during graceful shutdown");
+                }
+                Ok(Err(err)) => {
+                    tracing::error!(?err, "Server task failed during graceful shutdown");
+                }

Also applies to: 316-328

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2c51b87 and 02566ef.

📒 Files selected for processing (2)
  • plane/src/admin.rs (0 hunks)
  • plane/src/controller/mod.rs (3 hunks)
💤 Files with no reviewable changes (1)
  • plane/src/admin.rs
🔇 Additional comments (1)
plane/src/controller/mod.rs (1)

316-328: Verify impact on long-running handlers.

The 2-second timeout might affect long-running operations. Let's verify any handlers that might need special handling.

✅ Verification successful

Based on the search results, I can now provide a final response:

Timeout duration is appropriate for server termination

The 2-second TERMINATE_TIMEOUT_DURATION is suitable because:

  • Long-running operations are implemented as independent tasks/loops that can be aborted separately
  • The timeout only affects new incoming requests during shutdown, not existing operations
  • Key long-running operations have their own termination handling:
    • Backend status streaming (handle_backend_status_stream)
    • Drone sweep loop with explicit abort
    • Cleanup loop as a separate task
    • Heartbeat loop with sleep intervals

The timeout is specifically designed to handle new short-lived requests during shutdown, while existing long-running operations are handled through their respective cancellation mechanisms.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find potential long-running handlers that might be affected by the timeout

# Look for handlers with streaming or long-running patterns
rg -A 3 "Stream|stream|subscribe|watch|poll|long|infinite|loop" plane/src/controller/

# Look for handlers using sleep or delay
ast-grep --pattern 'sleep($$$)' 
ast-grep --pattern 'delay($$$)'

Length of output: 9319

@paulgb paulgb deleted the paulgb/add-timeout-to-termination branch November 15, 2024 22:38
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.

2 participants