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
- Investigate why the thread was interrupted (shutdown, executor timeout) and allow more time or retry the token request.
- Check Azure AD latency/proxy delays causing slow responses that hit timeouts.
- Ensure the interruption is not caused by a misconfigured timeout in the HTTP client; raise it if the network is slow.
- 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
- Avoid shutdownNow() on threads doing token exchanges
- Give long-running OAuth calls enough timeout headroom
- Use graceful shutdown with awaitTermination
- Retry interrupted token exchanges once the system is stable
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
- Cannot extract Azure Access Token from response
- Cannot obtain Azure Access Token. Details:
- Unable to get a token:
- Can not get Bitbucket user profile. HTTP code
- Connection to Azure marketplace failed. Details
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)