Skip to content

fix(spanner): retry additional transient InternalServerError errors - #19175

Merged
olavloite merged 1 commit into
mainfrom
spanner-retry-more-internal-errors
Nov 24, 2026
Merged

olavloite merged 1 commit into
mainfrom
spanner-retry-more-internal-errors

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Unify and expand retry handling for transient INTERNAL gRPC errors across streaming queries/reads and existing retried operations.

Previously, stream resumption and unary retry helpers checked slightly different subsets of error messages, causing transient HTTP/2, connection, and authentication backend errors to fail immediately instead of retrying.

With this change:

  • Streaming operations and retried operations share a single check that verifies the error is an InternalServerError before matching transient failure messages.
  • Retries now cover HTTP/2 INTERNAL_ERROR, unknown-cause connection closures, and transient authentication backend internal server errors in addition to RST_STREAM and unexpected EOS on DATA frames.
  • Non-retryable internal errors still fail immediately without retrying.
  • Synchronous and asynchronous unit and mock server tests cover both retryable and non-retryable internal error cases.

@olavloite
olavloite requested a review from a team as a code owner November 22, 2026 06:50

@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 internal error retry logic in google-cloud-spanner by replacing _check_rst_stream_error with _is_retryable_internal_error to support a broader range of retryable internal error messages. It also consolidates error handling blocks in snapshot.py and adds comprehensive unit and mock server tests. The review feedback highlights two potential issues in _helpers.py: first, a potential KeyError when performing a direct dictionary lookup on allowed_exceptions[exc.__class__] for subclasses of allowed exceptions, which can be resolved by using isinstance checks; second, a potential AttributeError when accessing exception.message directly, which can be avoided by using getattr safely.

Unify and expand retry handling for transient `INTERNAL` gRPC errors
across streaming queries/reads and existing retried operations.

Previously, stream resumption and unary retry helpers checked slightly
different subsets of error messages, causing transient HTTP/2,
connection, and authentication backend errors to fail immediately
instead of retrying.

With this change:
- Streaming operations and retried operations share a single check that
  verifies the error is an `InternalServerError` before matching
  transient failure messages.
- Retries now cover HTTP/2 `INTERNAL_ERROR`, unknown-cause connection
  closures, and transient authentication backend internal server errors
  in addition to `RST_STREAM` and unexpected EOS on `DATA` frames.
- Non-retryable internal errors still fail immediately without retrying.
- Synchronous and asynchronous unit and mock server tests cover both
  retryable and non-retryable internal error cases.
@olavloite
olavloite force-pushed the spanner-retry-more-internal-errors branch from f73307f to ec35dc6 Compare November 22, 2026 06:56
@olavloite

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 retry logic for internal errors in the Google Cloud Spanner client by replacing _check_rst_stream_error with a more comprehensive _is_retryable_internal_error predicate. This expands the list of retryable InternalServerError messages to include HTTP/2 internal errors, connection closures, and authentication backend errors, and consolidates exception handling in snapshot stream resumption. Extensive unit and mock server tests are also added. The review feedback suggests improving the exception class lookup in the _retry helper to robustly support subclasses of registered exceptions by dynamically checking inheritance with isinstance instead of performing a direct dictionary lookup on exc.__class__.

else:
stream_finished = True
except ServiceUnavailable:
del item_buffer[:]

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.

why are we removing this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's not 'removed'. It is consolidated into one except block. The ServiceUnavailable error was added to the except on line 180, as both blocks do the same thing.

@olavloite
olavloite merged commit c7c957d into main Nov 24, 2026
85 checks passed
@olavloite
olavloite deleted the spanner-retry-more-internal-errors branch November 24, 2026 11:42
daniel-sanche pushed a commit that referenced this pull request Nov 25, 2026
…19175)

Unify and expand retry handling for transient `INTERNAL` gRPC errors
across streaming queries/reads and existing retried operations.

Previously, stream resumption and unary retry helpers checked slightly
different subsets of error messages, causing transient HTTP/2,
connection, and authentication backend errors to fail immediately
instead of retrying.

With this change:
- Streaming operations and retried operations share a single check that
verifies the error is an `InternalServerError` before matching transient
failure messages.
- Retries now cover HTTP/2 `INTERNAL_ERROR`, unknown-cause connection
closures, and transient authentication backend internal server errors in
addition to `RST_STREAM` and unexpected EOS on `DATA` frames.
- Non-retryable internal errors still fail immediately without retrying.
- Synchronous and asynchronous unit and mock server tests cover both
retryable and non-retryable internal error cases.
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