SonarSource/sonarqube · error · IllegalStateException

Fail to request url:

Error message

Fail to request url: 

What it means

HttpConnector.doCall() executes an OkHttp Call synchronously; when call.execute() throws IOException (connection failure, DNS failure, timeout, SSL error, connection reset), it wraps it in IllegalStateException("Fail to request url: <url>"). The original IOException is the cause and pinpoints the network-level problem.

Source

Thrown at sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java:218

  private Request.Builder prepareOkRequestBuilder(WsRequest getRequest, HttpUrl.Builder urlBuilder) {
    Request.Builder okHttpRequestBuilder = new Request.Builder()
      .url(urlBuilder.build())
      .header("Accept", getRequest.getMediaType())
      .header("Accept-Charset", "UTF-8");
    if (systemPassCode != null) {
      okHttpRequestBuilder.header("X-Sonar-Passcode", systemPassCode);
    }
    getRequest.getHeaders().getNames().forEach(name -> okHttpRequestBuilder.header(name, getRequest.getHeaders().getValue(name).get()));
    return okHttpRequestBuilder;
  }

  private static Response doCall(OkHttpClient client, Request okRequest) {
    Call call = client.newCall(okRequest);
    try {
      return call.execute();
    } catch (IOException e) {
      throw new IllegalStateException("Fail to request url: " + okRequest.url(), e);
    }
  }

  private Response checkRedirect(Response response, RequestWithPayload<?> postRequest) {
    if (List.of(HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_TEMP_REDIRECT, HTTP_PERM_REDIRECT).contains(response.code())) {
      // OkHttpClient does not follow the redirect with the same HTTP method. A POST is
      // redirected to a GET. Because of that the redirect must be manually implemented.
      // See:
      // https://github.com/square/okhttp/blob/07309c1c7d9e296014268ebd155ebf7ef8679f6c/okhttp/src/main/java/okhttp3/internal/http/RetryAndFollowUpInterceptor.java#L316
      // https://github.com/square/okhttp/issues/936#issuecomment-266430151
      return followPostRedirect(response, postRequest);
    } else {
      return response;
    }
  }

  private Response followPostRedirect(Response response, RequestWithPayload<?> postRequest) {
    String location = response.header("Location");

View on GitHub (pinned to 184c821202)

Solutions

  1. Inspect the wrapped IOException cause to distinguish timeout vs connection-refused vs SSL error.
  2. Verify the server URL (host, port, context path) and that SonarQube is up (curl the URL).
  3. Configure proxy settings or trust store on the OkHttpClient passed to HttpConnector if behind a proxy or using self-signed TLS.
  4. Increase connect/read timeouts for large requests, and add retry logic for transient network failures.

Example fix

// before
HttpConnector connector = HttpConnector.newBuilder().url("http://sonar.example.com").build();
// after
HttpConnector connector = HttpConnector.newBuilder()
  .url("https://sonar.example.com")
  .connectTimeoutMs(10_000)
  .readTimeoutMs(60_000)
  .build();
Defensive patterns

Strategy: try-catch

Validate before calling

// before calling: verify reachability
HttpURLConnection c = (HttpURLConnection) new URL(baseUrl + "/api/system/status").openConnection();
c.setConnectTimeout(5000);
if (c.getResponseCode() != 200) throw new IllegalStateException("SonarQube unreachable at " + baseUrl);

Try / catch

try {
  WsResponse r = connector.call(request);
} catch (IllegalStateException e) {
  if (e.getCause() instanceof java.net.SocketTimeoutException) {
    // retry with backoff or increase timeouts
  } else if (e.getCause() instanceof java.net.ConnectException) {
    // server down / wrong host: alert operator
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling any WS operation when the SonarQube host is unreachable: wrong host/port in the connector configuration, server down, TLS certificate issues, socket/read timeout on slow responses, or no network route/firewall blocking the connection.

Common situations: SonarQube server stopped or restarting during CI; DNS not resolving the server hostname; corporate proxy required but not configured on the OkHttpClient; self-signed certificate not trusted; read timeout on large requests.

Related errors


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