Skip to content

Conversation

thiyaguk09
Copy link
Contributor

@thiyaguk09 thiyaguk09 commented Oct 7, 2025

Description

This change introduces new error handling logic in util.makeRequest to intercept and transform common low-level network and transport-layer failures into a consistent and actionable ApiError.

The following raw errors are now intercepted:

  • ECONNRESET
  • ETIMEDOUT
  • Generic messages containing "timed out"
  • Generic messages containing "TLS handshake"

These errors are transformed into a single ApiError with:

  • Code: 408, 503
  • Message: ["Connection reset by peer. This suggests the remote service is temporarily unavailable or overloaded.", "Request or TLS handshake timed out. This may be due to CPU starvation or a temporary network issue."]

This prevents the propagation of ambiguous, underlying network library errors and provides developers with a clear, unified diagnostic message, especially when operating in environments with high CPU contention.

Impact

The impact of this change is primarily positive, improving the developer experience:

  • Improved Error Diagnostics: Developers no longer need to parse various cryptic network codes (ECONNRESET, etc.). They will receive a clear, actionable message about the likely cause (CPU starvation/TLS failure).
  • Consistent Error Handling: Facilitates easier integration with custom error retry and logging mechanisms by providing a predictable error object (ApiError) rather than a raw Error.
  • No Breaking Changes: This is a purely additive fix that catches and transforms errors that would have been thrown anyway. It does not alter the successful path for requests.

Testing

Yes, unit tests were added.

  • A dedicated unit test suite, Network Connectivity Errors, was created under makeAuthenticatedRequestFactory to validate the new transformation logic.
  • Four separate unit tests were added to cover every specific condition:
    * should transform raw ECONNRESET into TLS ApiError
    * should transform raw "TLS handshake" into TLS ApiError
    * should transform raw generic "timed out" into TLS ApiError
    * should transform raw ETIMEDOUT into TLS ApiError

Tests Changed? No existing tests were modified.

Breaking Changes? No breaking changes are necessary.

Additional Information

  • TypeScript Note: Due to strict type definitions for BodyResponseCallback, the mock implementation required explicit type casting of the response and careful management of arguments to prevent type errors.
  • Stubbing: To ensure the tests did not timeout, the authClient was stubbed to guarantee successful authorization, forcing execution into the util.makeRequest path where the error injection and transformation occur.

Checklist

  • 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
  • Appropriate docs were updated
  • Appropriate comments were added, particularly in complex areas or places that require background
  • No new warnings or issues will be generated from this change

Fixes #

Transforms raw network errors (ECONNRESET, ETIMEDOUT, timed out, and TLS
handshake) into a specific ApiError (code 408) with a descriptive
message regarding potential CPU starvation.

This prevents misleading error propagation from the underlying request
library.
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: storage Issues related to the googleapis/nodejs-storage API. labels Oct 7, 2025
@thiyaguk09 thiyaguk09 changed the title Feat/improve tls error handling fix: Transform network failures into specific TLS timeout ApiError Oct 7, 2025
@thiyaguk09 thiyaguk09 marked this pull request as ready for review October 9, 2025 04:40
@thiyaguk09 thiyaguk09 requested review from a team as code owners October 9, 2025 04:40
@ddelgrosso1 ddelgrosso1 added the owlbot:run Add this label to trigger the Owlbot post processor. label Oct 14, 2025
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Oct 14, 2025
@ddelgrosso1
Copy link
Contributor

General comment but this logic will need to be ported to Gaxios in the future.

Splits network error handling: uses 408 for timeouts (timed out,
ETIMEDOUT, TLS handshake) and 503 for connection resets (ECONNRESET) to
improve retry logic accuracy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the googleapis/nodejs-storage API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants