Skip to content

fix(client): add connect and request timeouts#537

Open
dumko2001 wants to merge 7 commits intogoogleworkspace:mainfrom
dumko2001:fix/http-timeouts-v2
Open

fix(client): add connect and request timeouts#537
dumko2001 wants to merge 7 commits intogoogleworkspace:mainfrom
dumko2001:fix/http-timeouts-v2

Conversation

@dumko2001
Copy link
Contributor

@dumko2001 dumko2001 commented Mar 18, 2026

Description

Adds a 10-second connection timeout and a generous 10-minute (600s) request timeout to the HTTP client. This prevents the CLI and agents from hanging indefinitely while still allowing large file operations and API streams to complete successfully.

Checklist:

  • My code follows the AGENTS.md guidelines (no generated google-* crates).
  • I have run cargo fmt --all to format the code perfectly.
  • I have run cargo clippy -- -D warnings and resolved all warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have provided a Changeset file (e.g. via pnpx changeset) to document my changes.

@changeset-bot
Copy link

changeset-bot bot commented Mar 18, 2026

🦋 Changeset detected

Latest commit: ac994ca

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical reliability issue where the CLI could become unresponsive due to stalled Google API streams or dropped connections. By introducing explicit connection and request timeouts to the HTTP client, the changes ensure that network operations will eventually fail gracefully instead of hanging indefinitely, significantly improving the robustness of the application.

Highlights

  • HTTP Client Timeouts: Implemented a 10-second connection timeout and a 120-second request timeout for the HTTP client to prevent the CLI from hanging indefinitely.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 introduces connection and request timeouts for the HTTP client, a valuable change to prevent the application from hanging. My review includes one suggestion to improve code maintainability by replacing the hardcoded timeout values with named constants. This aligns with existing patterns in the file and makes the configuration clearer and easier to manage.

@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

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

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 adds connection and request timeouts to the HTTP client to prevent the CLI from hanging, which is a valuable improvement. The implementation is straightforward. However, the hardcoded 120-second request timeout may be too aggressive for large file transfers, potentially causing legitimate operations to fail. I've suggested increasing this value to better accommodate such use cases while still mitigating the risk of indefinite hangs.

@dumko2001
Copy link
Contributor Author

Updated to use named constants (CONNECT_TIMEOUT_SECS, REQUEST_TIMEOUT_SECS) for the timeout values as suggested.

@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

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

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 introduces connection and request timeouts to the HTTP client to prevent hangs. While adding a connection timeout is a a solid improvement, the global request timeout could unintentionally break long-running operations like large file downloads, as it applies to the entire request/response lifecycle. I've kept the critical comment with a suggestion to remove the global request timeout and instead encourage applying timeouts on a per-request basis where needed. If this change is made, the changeset file should also be updated to reflect that only a connect timeout was added.

reqwest::Client::builder()
.default_headers(headers)
.connect_timeout(std::time::Duration::from_secs(CONNECT_TIMEOUT_SECS))
.timeout(std::time::Duration::from_secs(REQUEST_TIMEOUT_SECS))
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

Setting a global request timeout on the reqwest::Client can cause issues with long-running operations, such as downloading large files or handling long-lived API streams. The timeout applies to the entire duration of the request, including reading the response body. This means any operation that legitimately takes longer than 120 seconds will fail, which could be a regression for some users.

To avoid breaking this functionality while still preventing indefinite hangs on most API calls, I recommend removing this global timeout from the client (and the corresponding REQUEST_TIMEOUT_SECS constant). Timeouts can then be applied on a per-request basis where appropriate (i.e., for API calls not expected to be long-running).

The connect_timeout is a great addition and doesn't have this side effect, so it should be kept.

@dumko2001
Copy link
Contributor Author

Removed the global request timeout as suggested. This avoids breaking long-running operations like large file downloads while still providing protection against connection hangs via the 10s connect_timeout.

@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

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

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 aims to prevent the CLI from hanging by adding connection and request timeouts to the HTTP client. The implementation successfully adds a 10-second connection timeout. However, the 120-second request timeout mentioned in the description is missing. I've provided a review comment to add the request timeout to fully address the issue of hanging on stalled streams. This is a critical part of the fix and should be included.

Comment on lines +22 to 23
.connect_timeout(std::time::Duration::from_secs(CONNECT_TIMEOUT_SECS))
.build()
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The pull request description mentions adding a 120-second request timeout, but this change is missing from the implementation. Adding a request timeout is crucial to prevent the client from hanging indefinitely when a stream stalls, which is one of the goals of this PR.

I've added the request timeout to the client builder. Please also define a REQUEST_TIMEOUT_SECS constant for the value 120 at the top of the file, similar to how CONNECT_TIMEOUT_SECS is defined.

Once this is done, please also update the changeset message in .changeset/http-timeouts.md to reflect the full scope of the changes.

        .connect_timeout(std::time::Duration::from_secs(CONNECT_TIMEOUT_SECS))
        .timeout(std::time::Duration::from_secs(120))
        .build()

@dumko2001
Copy link
Contributor Author

Re-added a 10-minute request timeout to prevent infinite hangs while still accommodating large file transfers, as suggested.

@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

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

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 adds connection and request timeouts to the HTTP client to prevent indefinite hangs. While the connection timeout is a beneficial addition, the global request timeout of 10 minutes could unintentionally break functionality for large file downloads or long-running API streams, as it applies to the entire request/response lifecycle. I have left a critical comment with a more detailed explanation and a suggestion to address this potential issue.

reqwest::Client::builder()
.default_headers(headers)
.connect_timeout(std::time::Duration::from_secs(CONNECT_TIMEOUT_SECS))
.timeout(std::time::Duration::from_secs(REQUEST_TIMEOUT_SECS))
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The global request timeout set with .timeout() might unintentionally break support for large file operations and long-running API streams.

According to the reqwest documentation, this timeout applies to the entire request-response lifecycle. For file downloads, this includes the time to download the complete file, and for streaming APIs, it applies to the entire duration of the stream.

A large file download (e.g., 1GB over a 10 Mbps connection) could take over 10 minutes, causing it to fail. Similarly, any API stream that needs to stay open for more than 10 minutes would be terminated. This seems to contradict the PR's goal of allowing these operations to complete successfully.

Consider removing the global .timeout() from the client builder for now. The connect_timeout is sufficient to prevent hangs on initial connection. A more robust solution for request timeouts would be to apply them on a per-request basis where appropriate, outside of the shared client configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants