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

feat: enable pre-emptive async oauth token refreshes #646

Merged
merged 21 commits into from May 20, 2021

Commits on Apr 29, 2021

  1. feat: add pre-emptive async oauth token refreshes

    This is currently a rough sketch and should not be merged. I just wanted to get some feedback here.
    
    The current implementation of oauth refresh offloads the IO to a separate executor, however when a token expires, all calls to getRequestMetadata would hang until the token is refreshed.
    This PR is a rough sketch to improve the situation by adding a stale state to token. If a token is within a minute of expiration, the first request to notice this, will spawn a refresh on the executor and immediately return with the existing token. This avoids hourly latency spikes for grpc.
    
    The implementation uses guava's ListenableFutures to manage the async refresh state. Although the apis are marked BetaApi in guava 19, they are GA in guava 30
    
    * The class introduces 3 distinct states:
      * Expired -  the token is not usable
      * Stale - the token is useable, but its time to refresh
      * Fresh - token can be used without any extra effort
    * All of the funtionality of getRequestMetadata has been extracted to asyncFetch. The new function will check if the token is unfresh and schedule a refresh using the executor
    * asyncFetch uses ListenableFutures to wrap state: if the token is not expired, an immediate future is returned. If the token is expired the future of the refresh task is returned
    * A helper refreshAsync 	& finishRefreshAsync are also introduced. They schedule the actual refresh and propagate the side effects
    * To handle blocking invocation: the async functionality is re-used but a DirectExecutor is used. All ExecutionErrors are unwrapped. In most cases the stack trace will be preserved because of the DirectExecutor. However if the async & sync methods are interleaved, it's possible that a sync call will await an async refresh task. In this case the callers stacktrace will not be present.
    igorbernstein2 committed Apr 29, 2021
    Copy the full SHA
    0e7326c View commit details
    Browse the repository at this point in the history
  2. minor doc

    igorbernstein2 committed Apr 29, 2021
    Copy the full SHA
    76f5c54 View commit details
    Browse the repository at this point in the history

Commits on Apr 30, 2021

  1. update broken test

    igorbernstein2 committed Apr 30, 2021
    Copy the full SHA
    30e3587 View commit details
    Browse the repository at this point in the history

Commits on May 3, 2021

  1. prep for merging with master: The initial async refresh feature was i…

    …mplemented on top of 0.8, so now I'm backporting features to minimize the merge conflicts
    igorbernstein2 committed May 3, 2021
    Copy the full SHA
    1be67a5 View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    c4e8955 View commit details
    Browse the repository at this point in the history
  3. in blocking mode, when a token is stale, only block the first caller …

    …and allow subsequent callers to use the stale token
    igorbernstein2 committed May 3, 2021
    Copy the full SHA
    8687928 View commit details
    Browse the repository at this point in the history
  4. Copy the full SHA
    383f65a View commit details
    Browse the repository at this point in the history
  5. minor tweaks and test

    igorbernstein2 committed May 3, 2021
    Copy the full SHA
    fa101b2 View commit details
    Browse the repository at this point in the history
  6. format

    igorbernstein2 committed May 3, 2021
    Copy the full SHA
    706ec19 View commit details
    Browse the repository at this point in the history
  7. Copy the full SHA
    bad38dd View commit details
    Browse the repository at this point in the history

Commits on May 4, 2021

  1. Copy the full SHA
    6ce036c View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    617d50c View commit details
    Browse the repository at this point in the history
  3. Copy the full SHA
    909b9e4 View commit details
    Browse the repository at this point in the history
  4. address feedback

    igorbernstein2 committed May 4, 2021
    Copy the full SHA
    b7b585b View commit details
    Browse the repository at this point in the history

Commits on May 5, 2021

  1. Copy the full SHA
    14f21e3 View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    f337392 View commit details
    Browse the repository at this point in the history

Commits on May 10, 2021

  1. Copy the full SHA
    a1c53f0 View commit details
    Browse the repository at this point in the history

Commits on May 12, 2021

  1. codestyle

    igorbernstein2 committed May 12, 2021
    Copy the full SHA
    a17186e View commit details
    Browse the repository at this point in the history

Commits on May 13, 2021

  1. Copy the full SHA
    a69c2b0 View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    b3d5605 View commit details
    Browse the repository at this point in the history

Commits on May 19, 2021

  1. Copy the full SHA
    a5a5a47 View commit details
    Browse the repository at this point in the history