Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exponential backoff can't be enabled for clients with credentials #2512

Open
dtrg opened this issue Sep 19, 2024 · 0 comments
Open

Exponential backoff can't be enabled for clients with credentials #2512

dtrg opened this issue Sep 19, 2024 · 0 comments
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: docs Improvement to the documentation for an API.

Comments

@dtrg
Copy link

dtrg commented Sep 19, 2024

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

, 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?

@zhumin8 zhumin8 added type: docs Improvement to the documentation for an API. priority: p3 Desirable enhancement or fix. May not be included in next release. labels Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: docs Improvement to the documentation for an API.
Projects
None yet
Development

No branches or pull requests

3 participants
@zhumin8 @dtrg and others