Skip to content

Add retry/backoff and request timeout to HTTP requests#21

Merged
stefanb merged 6 commits into
mainfrom
stefanb/add-retry-backoff-and-timeout
Jun 20, 2026
Merged

Add retry/backoff and request timeout to HTTP requests#21
stefanb merged 6 commits into
mainfrom
stefanb/add-retry-backoff-and-timeout

Conversation

@stefanb

@stefanb stefanb commented Jun 20, 2026

Copy link
Copy Markdown
Member

The Overpass API is rate-limited and occasionally overloaded, causing the daily update workflow to fail with no retry. Additionally, all HTTP requests lacked a timeout, meaning a stalled connection could hang the workflow indefinitely until the 15-minute job timeout killed it.

This adds a create_session_with_retries() helper that wraps requests.Session with urllib3's Retry strategy:

  • Retries up to 3 times on transient errors (429, 500, 502, 503, 504) with exponential backoff
  • Overpass API calls use a higher backoff factor (10s base, sleeping 10s/20s/40s) and explicitly enable POST retries since POST is not retried by default
  • saveurl() (OPSI downloads) uses a standard backoff factor (2s base, sleeping 2s/4s/8s) for GET requests
  • Overpass requests use a 360s timeout (exceeding the server-side 300s query timeout to allow for network overhead)
  • Standard downloads use a 120s timeout

No new dependencies are introduced -- urllib3 is already bundled with requests.

- Add create_session_with_retries() helper using urllib3 Retry strategy
- Retry on 429, 500, 502, 503, 504 with exponential backoff
- Overpass API uses higher backoff_factor (10s) due to rate limiting
- All requests now have a 120s timeout to prevent indefinite hangs

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI 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.

Pull request overview

Adds resilient HTTP behavior to the update.py data-fetch workflow to reduce failures/hangs caused by transient network/server issues (especially Overpass API rate-limiting).

Changes:

  • Introduces a create_session_with_retries() helper using requests + urllib3.Retry.
  • Applies retries/backoff to OPSI downloads and Overpass API calls (with higher backoff for Overpass).
  • Adds an explicit per-request timeout to avoid indefinite hangs.

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

Comment thread update.py Outdated
Comment thread update.py Outdated
Comment thread update.py
Comment thread update.py Outdated
stefanb and others added 3 commits June 20, 2026 07:50
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@stefanb stefanb requested a review from Copilot June 20, 2026 06:03
@stefanb stefanb marked this pull request as ready for review June 20, 2026 06:05

Copilot AI 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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment thread update.py Outdated
Comment thread update.py Outdated
Comment thread update.py
@stefanb stefanb merged commit d696fca into main Jun 20, 2026
1 check passed
@stefanb stefanb deleted the stefanb/add-retry-backoff-and-timeout branch June 20, 2026 06:29
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.

3 participants