SonarSource/sonarqube · error · IllegalStateException

Interrupted while getting a token:

Error message

Interrupted while getting a token: 

What it means

Same token-exchange flow as error 275, but the token request thread was interrupted while waiting for the OAuth response. The code restores the interrupt flag and throws IllegalStateException 'Interrupted while getting a token'.

Solutions

  1. Investigate why the thread was interrupted (shutdown, executor timeout) and allow more time or retry the token request.
  2. Check Azure AD latency/proxy delays causing slow responses that hit timeouts.
  3. Ensure the interruption is not caused by a misconfigured timeout in the HTTP client; raise it if the network is slow.
  4. Retry the operation after confirming the service is not shutting down.

Example fix

// before
ExecutorService pool = Executors.newFixedThreadPool(1);
pool.shutdownNow(); // interrupts in-flight token request
// after
pool.shutdown();
pool.awaitTermination(30, TimeUnit.SECONDS);
Defensive patterns

Strategy: retry

Validate before calling

// ensure the calling thread won't be interrupted mid-exchange
if (Thread.currentThread().isInterrupted()) { throw new IllegalStateException("Thread already interrupted; skip token exchange"); }

Try / catch

try { return oauthClient.getAccessTokenFromClientCredentialsGrantFlow(); } catch (IllegalStateException e) { if (e.getMessage().startsWith("Interrupted")) { Thread.currentThread().interrupt(); throw new RetriableException(e); } throw e; }

Prevention

When it happens

Trigger: The thread executing getAccessTokenFromClientCredentialsGrantFlow is interrupted (shutdown, timeout watchdog) while awaiting Azure AD's token response.

Common situations: Server shutdown mid-request; SonarQube request/thread timeouts; container orchestration terminating the process during a slow token call.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/0618438ccfd49eb8. Report an issue: GitHub.

Appendix: source

Thrown at server/sonar-server-common/src/main/java/org/sonar/server/oauth/OAuthMicrosoftRestClient.java:40

import com.github.scribejava.core.builder.ServiceBuilder;
import com.github.scribejava.core.oauth.OAuth20Service;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class OAuthMicrosoftRestClient {

  public String getAccessTokenFromClientCredentialsGrantFlow(String host, String clientId, String clientSecret, String tenant, String scope) {
    final OAuth20Service service = new ServiceBuilder(clientId)
      .apiSecret(clientSecret)
      .defaultScope(scope)
      .build(new ScribeMicrosoftOauth2Api(host, tenant));
    try {
      return service.getAccessTokenClientCredentialsGrant().getAccessToken();
    } catch (IOException | ExecutionException e) {
      throw new IllegalStateException("Unable to get a token: " + e);
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new IllegalStateException("Interrupted while getting a token: " + e);
    }
  }
}

View on GitHub (pinned to 184c821202)