b2-sdk-python icon indicating copy to clipboard operation
b2-sdk-python copied to clipboard

Faster upload token refresh on 5xx errors during uploads

Open ppolewicz opened this issue 5 months ago • 0 comments

When a server returns a 5xx error (e.g., 503 Service Unavailable) during file upload, the SDK now properly refreshes upload tokens instead of retrying with stale cached upload URLs a bunch of times first.

Previously, the HTTP layer would catch ServiceError and retry using the same pre-fetched upload URLs from the token pool. This caused repeated failures because the upload URLs may no longer be valid after a 5xx error and it delayed the recovery.

The fix introduces ServiceErrorDuringUpload exception that disables HTTP-level retries (similar to B2RequestTimeoutDuringUpload), forcing the error to propagate to the upload manager. The upload manager then clears cached tokens via clear_bucket_upload_data() and requests fresh upload URLs for retry attempts.

Changes:

  • Added ServiceErrorDuringUpload exception class
  • Convert ServiceError to ServiceErrorDuringUpload in b2http.py
  • Fixed RawSimulator to generate unique upload tokens per URL
  • Added comprehensive test for token refresh on 503 errors

Fixes Backblaze/B2_Command_Line_Tool#1118

ppolewicz avatar Oct 12 '25 00:10 ppolewicz