{"record":{"id":"a5851e4fb41f7047","repo":"SonarSource/sonarqube","slug":"fail-to-read-response-of-s","errorCode":null,"errorMessage":"Fail to read response of %s","messagePattern":"Fail to read response of (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java","lineNumber":90,"sourceCode":"  /**\n   * Get stream of characters, decoded with the charset\n   * of the Content-Type header. If that header is either absent or lacks a\n   * charset, this will attempt to decode the response body as UTF-8.\n   */\n  @Override\n  public Reader contentReader() {\n    return okResponse.body().charStream();\n  }\n\n  /**\n   * Get body content as a String. This response will be automatically closed.\n   */\n  @Override\n  public String content() {\n    try (ResponseBody body = okResponse.body()) {\n      return body.string();\n    } catch (IOException e) {\n      throw fail(e);\n    }\n  }\n\n  private RuntimeException fail(Exception e) {\n    throw new IllegalStateException(\"Fail to read response of \" + requestUrl(), e);\n  }\n\n  /**\n   * Equivalent to closing contentReader or contentStream.\n   */\n  @Override\n  public void close() {\n    okResponse.close();\n  }\n}\n","sourceCodeStart":72,"sourceCodeEnd":106,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/sonar-ws/src/main/java/org/sonarqube/ws/client/OkHttpResponse.java#L72-L106","documentation":"OkHttpResponse.content() reads the full response body of a SonarQube WS client response as a String. If reading the OkHttp ResponseBody throws an IOException, it is wrapped in an IllegalStateException with 'Fail to read response of <requestUrl>'. This means the HTTP request succeeded but the body could not be read (stream closed, connection dropped mid-body).","triggerScenarios":"Calling content() on a response whose underlying connection was closed/reset before or during body read; consuming the body after the response/connection was already closed or timed out; server aborting the response mid-transfer.","commonSituations":"Long responses over unstable connections; reading the body twice or after try-with-resources closed the response; server/proxy timeouts cutting large payloads; load balancers resetting idle connections.","solutions":["Read content() promptly, exactly once, while the response is open (don't cache the response across calls).","Retry the whole request — this failure is usually transient.","Increase OkHttp client read timeouts and enable keep-alive/retry-on-connection-failure.","Inspect the cause IllegalStateException's IOException for reset vs timeout; check proxy/LB idle timeout settings."],"exampleFix":"// before: body consumed after response closed\nString body;\ntry (Response r = call.execute()) {\n  bodyFuture.complete(r); // response closed here\n}\nString content = r.content(); // IllegalStateException\n\n// after: read while open, retry on failure\ntry (Response r = call.execute()) {\n  String content = r.content();\n}","handlingStrategy":"retry","validationCode":"// Ensure the response is ok and body present before reading:\nif (!response.isSuccessful() || response.contentLength() == -1) { /* handle error path before content() */ }","typeGuard":null,"tryCatchPattern":"try {\n  String body = wsResponse.content();\n} catch (IllegalStateException e) {\n  if (e.getCause() instanceof IOException) {\n    logger.warn(\"Body read failed for {} — retrying request\", e.getMessage());\n    body = retry(2, backoff(), wsClient::reissueAndRead);\n  } else throw e;\n}","preventionTips":["Call content() exactly once and while the response is still open.","Keep OkHttp read timeouts generous for large responses.","Don't store Response objects for later reading — extract content immediately.","Tune load balancer/proxy idle timeouts above client read durations."],"tags":["http","sonarqube-ws-client","okhttp","response-body"],"backgroundTag":"http-request-failed","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}