Skip to content

fix(spanner): add read timeout and disconnect to GCE metadata probe - #15288

Open
sakthivelmanii wants to merge 1 commit into
mainfrom
fix/spanner-gcp-metadata-probe-read-timeout
Open

sakthivelmanii wants to merge 1 commit into
mainfrom
fix/spanner-gcp-metadata-probe-read-timeout

Conversation

@sakthivelmanii

@sakthivelmanii sakthivelmanii commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem Statement

  • During Cloud Spanner client initialization, the one-time GCE metadata probe configured a connect timeout but omitted a read timeout and connection cleanup.
  • If the metadata endpoint or an intermediary proxy accepted the TCP connection without returning an HTTP response, client initialization could hang indefinitely while holding the JVM-wide location detection lock (LOCATION_LOCK) and the per-client built-in metrics provider lock, blocking other threads initializing Spanner clients or metrics.
  • Non-positive values for spanner.check_is_running_on_gcp_timeout could either disable timeouts (0) or fail client initialization with an IllegalArgumentException (< 0), and redirects or unbounded response lines were not bounded.

Solution

  • Apply the configured timeout to both connect and read timeouts on the GCE metadata probe, disable HTTP redirect following, inspect only the first response byte to detect a non-empty project ID, and unconditionally disconnect the HTTP connection in a finally block so the probe bounds how long LOCATION_LOCK and the per-client metrics provider lock can be held.
  • Validate spanner.check_is_running_on_gcp_timeout so trimmed positive integers are honored, while blank, non-numeric, 0, or negative values log a warning and fall back to the 5000 ms default.

@sakthivelmanii
sakthivelmanii requested review from a team as code owners November 30, 2026 20:04

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

Copy link
Copy Markdown
Contributor

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 refactors the GCP metadata server check in BuiltInMetricsProvider to be more robust and efficient. Key changes include introducing a new parseGcpCheckTimeoutMs helper to safely parse and validate the timeout system property, setting both connect and read timeouts on the connection, disabling redirect following, and optimizing response stream reading by inspecting only the first byte. Additionally, a comprehensive suite of unit tests has been added to BuiltInOpenTelemetryMetricsProviderTest to cover various edge cases, such as server hangs, redirects, and invalid configurations. There are no review comments to address.

@sakthivelmanii
sakthivelmanii force-pushed the fix/spanner-gcp-metadata-probe-read-timeout branch from 05eeb67 to e6cabd2 Compare November 30, 2026 20:36
## Problem Statement
- During Cloud Spanner client initialization, the one-time GCE metadata probe configured a connect timeout but omitted a read timeout and connection cleanup.
- If the metadata endpoint or an intermediary proxy accepted the TCP connection without returning an HTTP response, client initialization could hang indefinitely while holding the JVM-wide location detection lock (`LOCATION_LOCK`) and the per-client built-in metrics provider lock, blocking other threads initializing Spanner clients or metrics.
- Non-positive values for `spanner.check_is_running_on_gcp_timeout` could either disable timeouts (`0`) or fail client initialization with an `IllegalArgumentException` (`< 0`), and redirects or unbounded response lines were not bounded.

## Solution
- Apply the configured timeout to both connect and read timeouts on the GCE metadata probe, disable HTTP redirect following, inspect only the first response byte to detect a non-empty project ID, and unconditionally disconnect the HTTP connection in a `finally` block so the probe bounds how long `LOCATION_LOCK` and the per-client metrics provider lock can be held.
- Validate `spanner.check_is_running_on_gcp_timeout` so trimmed positive integers are honored, while blank, non-numeric, `0`, or negative values log a warning and fall back to the 5000 ms default.
@sakthivelmanii
sakthivelmanii force-pushed the fix/spanner-gcp-metadata-probe-read-timeout branch from e6cabd2 to 7e1abff Compare December 1, 2026 08:30

This branch has not been deployed

No deployments
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.

1 participant