googleapis / googleapis/google-api-java-client

Exponential backoff can't be enabled for clients with credentials

Đang mở
#2,512 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
priority: p3 type: feature request
Ngôn ngữ chính
Java
Star
1.5k
Fork
772
Merge trung bình
1 giờ 44 phút
Pull request đã merge (30 ngày)
1

Mô tả

Hello,

I've got a service which recently ran into issues. One of the AIs from the postmortem is that we should make sure that API client users use exponential backoff by default.

Currently, in order to enable exponential backoff you need to explicitly configure the HttpRequestInitializer object when creating the client interface. For example (from one of my tests):

```
var RETRYABLE_ERROR_CODES = ImmutableSet.of(403, 429);

return new Calendar.Builder(
transport,
GsonFactory.getDefaultInstance(),
/* httpRequestInitializer= */ request ->
request.setUnsuccessfulResponseHandler(
new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff())
.setBackOffRequired(
r -> RETRYABLE_ERROR_CODES.contains(r.getStatusCode()))))
[...elided...]
.build();
```

Except, in real life you're passing a GoogleAccountCredential object as the HttpRequestInitializer. This sets its own unsuccessful response handler (set in https://github.com/googleapis/google-api-java-client/blob/dd333371990ced9c76faba443bdb1b3738915410/google-api-client-android/src/main/java/com/google/api/client/googleapis/extensions/android/gms/auth/GoogleAccountCredential.java#L152, with the request handler at the bottom of the same class). While this does have its own backoff configuration, this is used only for the Oauth token fetch, and the unsuccessful response handler can't be configured.

This all seems extremely wrong. I don't see a way in which a client can use a credential _and_ configure exponential backoff, let alone by default. Our examples (e.g. https://developers.google.com/api-client-library/java) don't include any form of exponential backoff; I had to debug my way through the client code to find out it was supported at all.

Am I missing anything here?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.