Skip to content

fix: enhance error handling for Google Drive file downloads with SSL retries#1675

Open
ricofurtado wants to merge 3 commits into
mainfrom
google-drive-sync-retrial-mechanism
Open

fix: enhance error handling for Google Drive file downloads with SSL retries#1675
ricofurtado wants to merge 3 commits into
mainfrom
google-drive-sync-retrial-mechanism

Conversation

@ricofurtado
Copy link
Copy Markdown
Collaborator

@ricofurtado ricofurtado commented May 25, 2026

This pull request improves the reliability of file downloads in the Google Drive connector by adding robust retry logic for transient SSL and network errors during the file download process. The main changes are as follows:

Resilience improvements for file downloads:

  • Added retry logic to _download_file_bytes to handle transient ssl.SSLError, ConnectionResetError, and TimeoutError exceptions, with exponential backoff and logging for each retry attempt. Each retry re-creates the downloader to avoid partial-buffer state. [1] [2]
  • Imported the ssl module to support the new error handling.ss

Summary by CodeRabbit

  • Bug Fixes
    • Improved Google Drive download reliability with automatic retries and backoff for transient network errors
    • Non-downloadable document types now automatically convert to compatible formats (e.g., export to PDF) to allow download
    • Reduced failures from temporary connectivity or transfer interruptions, improving overall download success rate

Review Change Stack

@github-actions github-actions Bot added the backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) label May 25, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 711036b0-8f12-4dbd-94cd-3f05d0de720f

📥 Commits

Reviewing files that changed from the base of the PR and between c8f2543 and 8507b4a.

📒 Files selected for processing (1)
  • src/connectors/google_drive/connector.py

Walkthrough

Google Drive connector now retries failed byte-downloads up to 3 times on transient SSL, connection, and timeout errors using exponential backoff. The BytesIO buffer and MediaIoBaseDownload object are recreated per attempt, and the existing fileNotDownloadable fallback to PDF export is integrated into the retry flow.

Changes

Google Drive Download Resilience

Layer / File(s) Summary
Transient error retry and backoff
src/connectors/google_drive/connector.py
ssl module imported and Google Drive byte-download wrapped in 3-attempt retry loop that catches ssl.SSLError, ConnectionResetError, and TimeoutError with exponential backoff. fileNotDownloadable handling preserved and integrated into retry flow to recover from transport failures and misclassified Google Docs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding retry logic with SSL error handling for Google Drive downloads, which matches the core implementation of retrying on ssl.SSLError, ConnectionResetError, and TimeoutError with exponential backoff.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch google-drive-sync-retrial-mechanism

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added bug 🔴 Something isn't working. and removed bug 🔴 Something isn't working. labels May 25, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/connectors/google_drive/connector.py (1)

516-517: 💤 Low value

Consider making retry parameters configurable.

The hardcoded _max_retries = 3 and exponential backoff formula 2.0**_attempt could be class constants or config parameters to allow tuning based on operational needs.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/connectors/google_drive/connector.py` around lines 516 - 517, The retry
loop currently uses hardcoded _max_retries = 3 and exponential backoff
2.0**_attempt; refactor these into configurable parameters by introducing
class-level constants (e.g., MAX_RETRIES and BACKOFF_BASE) or instance
attributes set via the connector's __init__ (e.g., self.max_retries,
self.backoff_base) and replace uses of _max_retries and 2.0**_attempt with those
symbols (keep the loop variable _attempt). Ensure defaults preserve current
behavior (3 and 2.0) but allow callers or config to override for tuning.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/connectors/google_drive/connector.py`:
- Around line 545-559: The retry sleep is executed while holding self._lock
which blocks concurrent downloads; modify the retry logic in the download loop
around MediaIoBaseDownload.next_chunk() so the lock is released before sleeping:
inside the except (ssl.SSLError, ConnectionResetError, TimeoutError) handler set
flags/locals (_should_retry = _attempt < _max_retries - 1, _delay =
2.0**_attempt, _err = e) and break/return from the locked section, then outside
the with self._lock block perform logger.warning(...) and time.sleep(_delay) if
_should_retry or re-raise _err if not; alternatively reduce the lock scope to
only the code that constructs the HttpRequest/self.service.files() call so
MediaIoBaseDownload.next_chunk() and retry-sleeps run without holding self._lock
(referencing self._lock, MediaIoBaseDownload.next_chunk, _attempt, _max_retries,
logger, file_id).

---

Nitpick comments:
In `@src/connectors/google_drive/connector.py`:
- Around line 516-517: The retry loop currently uses hardcoded _max_retries = 3
and exponential backoff 2.0**_attempt; refactor these into configurable
parameters by introducing class-level constants (e.g., MAX_RETRIES and
BACKOFF_BASE) or instance attributes set via the connector's __init__ (e.g.,
self.max_retries, self.backoff_base) and replace uses of _max_retries and
2.0**_attempt with those symbols (keep the loop variable _attempt). Ensure
defaults preserve current behavior (3 and 2.0) but allow callers or config to
override for tuning.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6330db09-dff0-41e7-b66e-1487e2cf467f

📥 Commits

Reviewing files that changed from the base of the PR and between 0961fd1 and c8f2543.

📒 Files selected for processing (1)
  • src/connectors/google_drive/connector.py

Comment thread src/connectors/google_drive/connector.py Outdated
@github-actions github-actions Bot added bug 🔴 Something isn't working. and removed bug 🔴 Something isn't working. labels May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) bug 🔴 Something isn't working.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant