Skip to content

Cancelling one asynchronous token request cancels other callers sharing its refresh #427

Closed as not planned

Description

@sylvesterkaczmarek

The asynchronous token cache returns its internal in-flight CompletableFuture directly to every caller waiting for the same refresh. Cancelling any returned future therefore cancels the shared operation from the other callers' perspective. A later caller can also receive the already-cancelled future while the provider is still working.

A deterministic reproduction is to make an AccessTokenProvider return a manually controlled future, call CachingAccessTokenProvider.getAsync twice, cancel the first returned future, and then complete the provider's future successfully. The second caller receives CancellationException rather than the provider's token.

This also affects the chained forced-refresh path: cancelling the original returned future can trigger the next provider call before the original provider has finished. Explicitly completing a caller's returned future likewise completes every other caller's shared result.

Each caller should own its returned future while the cache owns the shared refresh future. Cancelling or completing one caller's future should not settle another caller or change when a forced provider refresh starts.

Six controlled-future tests reproduce five failures on main; the advisory-refresh control passes. No sleeps, network calls or live credentials are needed. This is distinct from #426, which handles exceptions while launching a refresh.

Activity

  1. tomer-ant commented on Oct 14, 2026

    @tomer-ant
    Contributor

    Closing as not planned. The token cache and its futures are internal. Callers only receive futures derived with thenApply, and cancelling one doesn't reach the shared refresh. See #413 (comment) for context on how we're handling this batch of reports. If you hit this in real usage, reply with the details and we'll reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions