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 connection timeout #837

Merged
merged 2 commits into from
Nov 4, 2024
Merged

Add connection timeout #837

merged 2 commits into from
Nov 4, 2024

Conversation

paulgb
Copy link
Member

@paulgb paulgb commented Nov 4, 2024

We used to have a timeout on the lifespan of the entire request, which also captured an initial connection timeout, but also failed for long-lived connections like large requests. When we removed that timeout, we also removed the ability to time-out a request when the initial TCP connection hangs.

This adds back a timeout that only applies to the initial connection.

Copy link

vercel bot commented Nov 4, 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 4, 2024 8:28pm

Copy link
Contributor

coderabbitai bot commented Nov 4, 2024

📝 Walkthrough

Walkthrough

This pull request introduces several changes to the plane-dynamic-proxy package. The Cargo.toml file has been updated to include two new dependencies: tower-service at version 0.3.3 and futures-util at version 0.3.30, which is also included in the [dev-dependencies]. The version of the package remains at 0.5.1. In the source code, a new struct named TimeoutHttpConnector is added in connector.rs, which wraps around hyper_util::client::legacy::connect::HttpConnector and incorporates a timeout feature for connection establishment. This struct implements the tower_service::Service<Uri> trait, providing methods for connection management and error handling through a custom error enum, TimeoutHttpConnectorError. The ProxyClient structure in proxy.rs is updated to use TimeoutHttpConnector instead of the previous HttpConnector. Additionally, a new public module connector is declared in lib.rs. Finally, the tests in plane-tests/tests/proxy.rs have been expanded to cover various scenarios for the proxy server, ensuring comprehensive functionality checks.

Possibly related PRs

  • Refactor proxy #814: Updates dependencies in Cargo.toml, directly related to the dependency management changes in this PR.
  • Update Axum version in proxy #817: Updates the Axum version, which may impact the dependencies listed in the main PR's Cargo.toml.
  • Bump to v0.5.0 #821: Updates the version of the dynamic-proxy package, directly related to the changes in dependency management in this PR.
  • Version 0.5.1 #830: Renames the dynamic-proxy package to plane-dynamic-proxy, reflecting changes in the package structure relevant to this PR.

Suggested reviewers

  • rolyatmax
  • michaelsilver

🪧 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 1cc90d9 into main Nov 4, 2024
6 checks passed
@paulgb paulgb deleted the paulgb/add-connection-timeout branch November 4, 2024 20:39
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 (7)
dynamic-proxy/src/lib.rs (1)

2-2: LGTM! Consider adding module documentation.

The addition of the public connector module is well-structured and appropriately placed. The public visibility is correct as it needs to expose the timeout functionality.

Consider adding module-level documentation (//! comments) in connector.rs to describe:

  • The purpose and functionality of the TimeoutHttpConnector
  • Usage examples
  • Any configuration options for timeouts
dynamic-proxy/Cargo.toml (1)

26-27: LGTM! Dependencies align well with the connection timeout implementation.

The addition of tower-service and futures-util is appropriate for implementing the connection timeout functionality. The versions chosen are stable and widely used.

Consider using semantic versioning ranges for better flexibility in minor updates:

-tower-service = "0.3.3"
-futures-util = "0.3.30"
+tower-service = "0.3"
+futures-util = "0.3"
dynamic-proxy/src/proxy.rs (3)

17-20: Address the TODO comment for the timeout field.

The timeout field is marked as unused but has a default value of 10 seconds. Consider either:

  1. Implementing the timeout configuration functionality
  2. Removing the field if it's no longer needed with the new TimeoutHttpConnector

Would you like me to help implement the timeout configuration or open an issue to track this task?


Line range hint 30-34: Consider making the connection timeout configurable.

While using TimeoutHttpConnector::default() works, it would be beneficial to:

  1. Document the default connection timeout value
  2. Allow configuration of the timeout duration through the ProxyClient::new() method

Consider this approach:

- pub fn new() -> Self {
+ pub fn new() -> Self {
+     Self::with_timeout(DEFAULT_TIMEOUT)
+ }
+
+ pub fn with_timeout(connection_timeout: Duration) -> Self {
     let client = Client::builder(TokioExecutor::new())
-        .build(TimeoutHttpConnector::default());
+        .build(TimeoutHttpConnector::new(connection_timeout));
     Self {
         client,
         timeout: DEFAULT_TIMEOUT,
     }
 }

Missing error mapping between TimeoutHttpConnectorError and ProxyError

The verification reveals a gap in error handling. While both TimeoutHttpConnectorError and ProxyError have appropriate timeout variants, there is no impl From<TimeoutHttpConnectorError> for ProxyError to properly map between them. This means timeout errors from the connector might not be correctly translated to ProxyError::Timeout.

  • Add an implementation to map TimeoutHttpConnectorError::Timeout to ProxyError::Timeout
  • Map TimeoutHttpConnectorError::Boxed to ProxyError::RequestFailed

Example implementation:

impl From<TimeoutHttpConnectorError> for ProxyError {
    fn from(err: TimeoutHttpConnectorError) -> Self {
        match err {
            TimeoutHttpConnectorError::Timeout => ProxyError::Timeout,
            TimeoutHttpConnectorError::Boxed(e) => ProxyError::RequestFailed(e),
        }
    }
}
🔗 Analysis chain

Line range hint 44-63: Verify error mapping for TimeoutHttpConnector.

The error handling looks good, but let's verify that the new TimeoutHttpConnector's timeout errors are properly mapped to ProxyError::Timeout.


Let me gather more information to verify how these connector errors are mapped to ProxyError.


Let me check one more thing to see how ProxyError is defined and if there are any direct uses of these error types.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check how TimeoutHttpConnector errors are handled

# Test: Look for error mapping in the connector implementation
ast-grep --pattern 'impl From<$_> for $_Error {
  $$$
}'

# Test: Look for error type definitions and conversions
rg -A 5 'TimeoutHttpConnectorError'

Length of output: 1728


Script:

#!/bin/bash
# Check how TimeoutHttpConnectorError is converted to ProxyError
ast-grep --pattern 'impl From<TimeoutHttpConnectorError> for ProxyError {
  $$$
}'

# Look for other places where TimeoutHttpConnectorError is handled
rg -A 3 'TimeoutHttpConnectorError::Timeout'

Length of output: 351


Script:

#!/bin/bash
# Look for ProxyError definition and its variants
rg -A 10 'enum ProxyError'

# Look for any direct error handling between these types
rg '(TimeoutHttpConnectorError|ProxyError)' --type rust

Length of output: 2010

dynamic-proxy/src/connector.rs (2)

10-13: Encapsulate struct fields by making them private.

To enhance encapsulation and prevent unintended external modification, consider making the timeout and connector fields private. If external access or modification is necessary, provide appropriate getter and setter methods or builder patterns.


49-56: Avoid boxing errors to preserve error information.

Using Box<dyn std::error::Error + Send + Sync> can obscure specific error types, making debugging more challenging. Instead, consider defining specific error variants in TimeoutHttpConnectorError to represent common errors from the underlying connector. This approach improves error transparency and can potentially enhance performance by avoiding dynamic dispatch.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 27f1fd9 and 34759de.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • dynamic-proxy/Cargo.toml (1 hunks)
  • dynamic-proxy/src/connector.rs (1 hunks)
  • dynamic-proxy/src/lib.rs (1 hunks)
  • dynamic-proxy/src/proxy.rs (2 hunks)
  • plane/plane-tests/tests/proxy.rs (0 hunks)
💤 Files with no reviewable changes (1)
  • plane/plane-tests/tests/proxy.rs
🔇 Additional comments (1)
dynamic-proxy/src/proxy.rs (1)

3-3: LGTM: Import changes align with the new timeout functionality.

The imports correctly bring in the new TimeoutHttpConnector and the legacy Client implementation.

Also applies to: 9-9

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