-
Notifications
You must be signed in to change notification settings - Fork 323
fix: updates timeout/retry code to respect hanging server #2408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: updates timeout/retry code to respect hanging server #2408
Conversation
Summary of ChangesHello @chalmerlowe, 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 significantly improves the stability and predictability of the BigQuery client library by addressing critical issues in error handling and timeout management. It ensures that the retry mechanism can robustly handle various gRPC error formats without crashing and guarantees that data retrieval operations from the BigQuery Storage API will respect specified timeouts, preventing unresponsive client states. Highlights
Using Gemini Code AssistThe 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
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 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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this 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 addresses a crash in retry logic and ensures proper timeout propagation. The changes in google/cloud/bigquery/retry.py add robust error inspection to handle unstructured gRPC errors, while the updates in google/cloud/bigquery/table.py and google/cloud/bigquery/_pandas_helpers.py ensure that the user-specified timeout is correctly passed down to the underlying to_arrow and create_read_session calls. A new test case is added to verify the timeout propagation.
Added debug level logging to respond to comment and cleaned up some comments.
| except (AttributeError, IndexError, TypeError, KeyError): | ||
| # Fallback for when errors attribute is missing, empty, or not a dict | ||
| # or doesn't contain "reason" (e.g. gRPC exceptions). | ||
| _LOGGER.debug("Inspecting unstructured error for retry: %r", exc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE to reviewer:
Why did we use %r in the string to use repr() to output the exception? To reduce unnecessary work by using lazy evaluation.
In the Python logging module, the old-style % syntax is often preferred for performance. It allows the logger to skip the string formatting entirely if the log level (DEBUG) is not enabled. With f-strings, the string is eagerly evaluated as soon as the function is called, even if logging is turned off or the display level means the message won't be captured.
Because this code is not in a super-tight loop, the difference is negligible, but none-the-less it is good practice.
| for page in pages: | ||
| yield _row_iterator_page_to_arrow(page, column_names, arrow_types) | ||
| else: | ||
| start_time = time.monotonic() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE to reviewer:
Why a monotonic clock? A monotonic clock is guaranteed to move forward or stay still, but never go backward, making it ideal for measuring elapsed time and durations, unlike the system's wall clock (time.time()), which can be adjusted manually or by network time protocols (NTP) (i.e. fall back in the fall). Not likely to be a huge issue here, but good practice for this use case.
Description
This PR fixes a crash when handling
_InactiveRpcErrorduring retry logic and ensures propertimeoutpropagation inRowIterator.to_dataframe.Fixes
Retry Logic Crash: Addressed an issue in
google/cloud/bigquery/retry.pywhere_should_retrywould raise aTypeErrorwhen inspecting unstructuredgRPCerrors (like_InactiveRpcError). The fix adds robust error inspection to fallback gracefully whenexc.errorsis not subscriptable.Timeout Propagation: Added the missing
timeoutparameter toRowIterator.to_dataframeingoogle/cloud/bigquery/table.py. This ensures that the user-specifiedtimeoutis correctly passed down to the underlyingto_arrowcall, preventing the client from hanging indefinitely when the Storage API is unresponsive.Changes
Modified
google/cloud/bigquery/retry.py: Updated_should_retryto handleTypeErrorandKeyErrorwhen accessingexc.errors.Modified
google/cloud/bigquery/table.py: UpdatedRowIterator.to_dataframesignature and implementation to accept and pass thetimeoutparameter.The first half of this work was completed in PR #2354