nodecraft / b2-cloud-storage

Backblaze B2 Cloud Storage API Client. Implements all of the B2 Cloud Storage APIs, with helper methods for uploading files.
MIT License
42 stars 10 forks source link

Handle 503/service_unavailable errors #25

Closed Cherry closed 4 years ago

Cherry commented 4 years ago

Occasionally when uploading files, even after an upload URL has been retrieved, B2 can respond with the following when attempting to upload:

{
  "code": "service_unavailable",
  "message": "c001_v0001113_t0035 is too busy",
  "status": 503
}

This is by design, and should trigger this library to attempt to get a new upload URL and retry.

We handle this more gracefully (-ish) in uploadFileSmall, but do not handle it at all in uploadFileLarge. For uploadFileSmall, we should be requesting a new upload URL on a retry, rather than just uploading again to the "too busy" URL. For uploadFileLarge, this check would would probably make sense around line 1402 of index.js, replacing the upload URL we just used and got an error from, with a new one.

Testing should be done as per https://www.backblaze.com/b2/docs/integration_checklist.html. A header can be set to simulate artificial errors.