Skip to content

Fix: UnboundLocalError and improve download resilience with automatic retries#4

Open
AnderCMD wants to merge 5 commits into
daferferso:masterfrom
AnderCMD:master
Open

Fix: UnboundLocalError and improve download resilience with automatic retries#4
AnderCMD wants to merge 5 commits into
daferferso:masterfrom
AnderCMD:master

Conversation

@AnderCMD

@AnderCMD AnderCMD commented Apr 20, 2026

Copy link
Copy Markdown

This PR addresses a crash during the synchronization process and improves the overall reliability of the extractor when facing network instability.

Changes:
Fixed UnboundLocalError in WaBackup.get:
Previously, the get method would catch RequestException but attempt to return the response variable even if it was never assigned. The method now correctly handles exceptions by raising them after logging, ensuring the flow is properly managed.

Implemented Automatic Retries:
Integrated requests.Session with a urllib3.util.Retry strategy.
The client now automatically retries failed requests up to 5 times with an exponential backoff. This prevents crashes caused by transient network issues (like DNS resolution failures or temporary connection drops).

Improved Download Resilience:
Refactored fetch_all to handle individual file failures gracefully. If a file fails to download after all retries, the process now logs the error and continues with the remaining files instead of halting the entire synchronization.
Added connection pooling via requests.Session for better performance during large backups (10,000+ files).

Enhanced User Feedback:
Added more descriptive error messages when a request or a specific file fetch fails.

Technical Details:
Retries: Configured for common status codes (429, 500, 502, 503, 504).
Exception Handling: Wrapped file fetching in a try-except block within the thread pool worker to ensure thread safety and continuity.

Copilot AI review requested due to automatic review settings April 20, 2026 17:55
@AnderCMD AnderCMD changed the title feat: implement request retries with session management and update authentication credentials Fix: UnboundLocalError and improve download resilience with automatic retries Apr 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Implements a reusable requests.Session with retry behavior for Google Backup API calls, and updates download flow/error handling to better tolerate per-file failures.

Changes:

  • Add requests.Session configured with HTTPAdapter + urllib3.Retry and route WaBackup.get() through it.
  • Change request exception handling to raise on failure (instead of swallowing) and return the Response on success.
  • Make fetch() return None on failure and update fetch_all() to skip checksum/size accounting for failed downloads.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread main.py Outdated
Comment thread main.py
Comment thread main.py
AnderCMD and others added 2 commits April 20, 2026 12:03
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@AnderCMD

Copy link
Copy Markdown
Author

@copilot apply changes based on the comments in this thread

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