Repository navigation
fix(spanner): add read timeout and disconnect to GCE metadata probe - #15288
Open
sakthivelmanii wants to merge 1 commit into
Open
sakthivelmanii wants to merge 1 commit into
sakthivelmanii wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
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
force-pushed
the
fix/spanner-gcp-metadata-probe-read-timeout
branch
from
November 30, 2026 20:36
05eeb67 to
e6cabd2
Compare
## 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
force-pushed
the
fix/spanner-gcp-metadata-probe-read-timeout
branch
from
December 1, 2026 08:30
e6cabd2 to
7e1abff
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem Statement
LOCATION_LOCK) and the per-client built-in metrics provider lock, blocking other threads initializing Spanner clients or metrics.spanner.check_is_running_on_gcp_timeoutcould either disable timeouts (0) or fail client initialization with anIllegalArgumentException(< 0), and redirects or unbounded response lines were not bounded.Solution
finallyblock so the probe bounds how longLOCATION_LOCKand the per-client metrics provider lock can be held.spanner.check_is_running_on_gcp_timeoutso trimmed positive integers are honored, while blank, non-numeric,0, or negative values log a warning and fall back to the 5000 ms default.