git-lfs/tq
Chris Darroch 0f82147ad5 lfshttp,tq,t: don't fail on retriable batch errors
A prior commit in this PR resolves a bug where a 429 response to an
upload or download request causes a Go panic in the client if the
response lacks a Retry-After header.

The same condition, when it occurs in the response to a batch API
request, does not trigger a Go panic; instead, though, we simply
fail without retrying the batch API request at all.  This stands
in constrast to how we now handle 429 responses for object uploads
and downloads when no Retry-After header is provided, because in
that case, we perform multiple retries, following the exponential
backoff logic introduced in PR #4097.

This difference stems in part from the fact that the download()
function of the basicDownloadAdapter structure and the DoTransfer()
function of the basicUploadAdapter structure both handle 429 responses
by first calling the NewRetriableLaterError() function of the "errors"
package to try to parse any Retry-After header, and if that returns
nil, then calling the NewRetriableError() function, so they always
return some form of retriable error after a 429 status code is received.

We therefore modify the handleResponse() method of the Client structure
in the "lfshttp" package to likewise always return a retriable error
of some kind after a 429 response.  If a Retry-After header is found
and is able to be parsed, then a retriableLaterError (from the "errors"
package) is returned; otherwise, a generic retriableError is returned.

This change is not sufficient on its own, however.  When the batch
API returns 429 responses without a Retry-After header, the transfer
queue now retries its requests following the exponential backoff
logic, as we expect.  If one of those eventually succeeds, though,
the batch is still processed as if it encountered an unrecoverable
failure, and the Git LFS client ultimately returns a non-zero exit code.

The reason this occurs is because the enqueueAndCollectRetriesFor()
method of the TransferQueue structure in the "tq" package sets the
flag which causes it to return an error for the batch both when an
object in the batch cannot be retried (because it has reached its
retry limit) or when an object in the batch can be retried but no
specific retry wait time was provided by a retriableLaterError.

The latter of these two cases is what is now triggered when the batch
API returns a 429 status code and no Retry-After header.  In commit
a3ecbcc7f6bf27aedbcdaf830bd186dba4a7328f of PR #4573 this code was
updated to improve how batch API 429 responses with Retry-After headers
are handled, building on the original code introduced in PR #3449
and some fixes in PR #3930.  This commit added the flag, named
hasNonScheduledErrors, which is set if any objects in a batch which
experiences an error either can not be retried, or can be retried but
don't have a specific wait time as provided by a Retry-After header.
If the flag is set, then the error encountered during the processing
of the batch is returned by the enqueueAndCollectRetriesFor() method,
and although it is wrapped by NewRetriableError function, because the
error is returned instead of just a nil, it is collected into the errors
channel of the queue by the collectBatches() caller method, and this
ultimately causes the client to report the error and return a non-zero
exit code.

By constrast, the handleTransferResult() method of the TransferQueue
structure treats retriable errors from individual object uploads and
downloads in the same way for both errors with a specified wait time
and those without.

To bring our handling of batch API requests into alignment with
this approach, we can simply avoid setting the flag variable when
a batch encounters an error and an object can be retried but without
a specified wait time.

We also rename the flag variable to hasNonRetriableObjects, which
better reflects its meaning, as it signals the fact that at least
one object in the batch can not be retried.  As well, we update
some related comments to clarify the current actions and intent of
this section of code in the enqueueAndCollectRetriesFor() method.

We then add a test to the t/t-batch-retries-ratelimit.sh test suite
like the ones we added to the t/t-batch-storage-retries-ratelimit.sh
script in a previous commit in this PR.  The test relies on a new
sentinel value in the test repository name which now recognize in
our lfstest-gitserver test server, and which causes the test server
to return a 429 response to batch API requests, but without a
Retry-After header.  This test fails without both of the changes
we make in this commit to ensure we handle 429 batch API responses
without Retry-After headers.
2024-06-19 00:55:03 -07:00
..
schemas tq,lfsapi/ssh: convert int64 to int 2017-04-05 14:46:45 -06:00
adapterbase.go make additional message strings translatable 2022-01-29 22:36:19 -08:00
api_test.go tq/api_test.go: remove unneeded translations 2022-01-29 22:32:57 -08:00
api.go tq: make Manifest an interface 2023-03-23 16:55:57 +00:00
basic_download.go Fix panic caused by accessing non-existent header 2024-06-18 17:28:29 +08:00
basic_upload.go Fix panic caused by accessing non-existent header 2024-06-18 17:28:29 +08:00
custom_test.go Set package version to v3 2021-09-02 20:41:08 +00:00
custom.go tq: make Manifest an interface 2023-03-23 16:55:57 +00:00
errors_test.go tq/errors: implement MalformedObjectError 2017-03-24 14:36:59 -06:00
errors.go tq: make strings translatable 2022-01-18 17:38:25 +00:00
manifest_test.go Set package version to v3 2021-09-02 20:41:08 +00:00
manifest.go tq/manifest.go: lookup standalone endpoint once 2023-10-17 10:55:16 -07:00
meter.go avoid extra message format parsing where possible 2022-01-29 22:32:58 -08:00
ssh.go tq: lazily initialize PktlineConnection 2024-01-29 20:07:48 +00:00
transfer_queue_test.go tq: add exponential backoff for retries 2020-04-15 14:10:16 -07:00
transfer_queue.go lfshttp,tq,t: don't fail on retriable batch errors 2024-06-19 00:55:03 -07:00
transfer_test.go tq/transfer_test.go: enable and fix all tests 2023-07-26 17:58:12 -07:00
transfer.go tq/transfer: copy Id and Token 2023-10-02 16:22:02 -04:00
tus_upload.go Replace deprecated io/ioutil functions 2024-01-11 03:48:51 +08:00
verify_test.go Set package version to v3 2021-09-02 20:41:08 +00:00
verify.go Set package version to v3 2021-09-02 20:41:08 +00:00