Skip to content

Conversation

ptpt
Copy link
Member

@ptpt ptpt commented Aug 28, 2025

This pull request enhances the upload retry logic in mapillary_tools/uploader.py to handle rate-limiting and server errors more robustly. The main improvements include more precise parsing of HTTP response headers and error bodies to determine retryability and wait times, and refactoring the retry logic to support these changes.

Retry Logic Improvements:

  • Refactored _is_retriable_exception to return a tuple (retriable: bool, retry_after_sec: int) instead of just a boolean, enabling more granular control over retry timing based on server responses and headers. Added comprehensive docstring and test examples.
  • Added _parse_backoff and _parse_retry_after_from_header helpers to extract backoff durations from JSON responses and the Retry-After HTTP header, supporting both integer seconds and RFC 2822 date formats.
  • Improved handling of HTTP 429 (rate limit) and 5xx (server) errors to always retry with an appropriate delay, even if the error body marks them as non-retriable, following best practices for rate-limited APIs.

Uploader Exception Handling:

  • Updated _handle_upload_exception to use the new retry logic, including dynamic sleep durations based on server-provided backoff and Retry-After values.

Dependencies:

  • Added imports for datetime and email.utils to support parsing of Retry-After header values.

@meta-cla meta-cla bot added the cla signed label Aug 28, 2025
@ptpt ptpt merged commit e18083f into main Aug 28, 2025
16 checks passed
@ptpt ptpt deleted the fix-retry-on-upload-rate-limit branch August 28, 2025 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant