← Back to Pull requests

SOLR-18665: Make the start readiness wait work for TLS setups #5368

Open
janhoy opened this pull request with 208 lines diff across 7 files
View on GitHub
janhoy janhoy commented on Nov 20, 2026 09:10 UTC
Author

https://issues.apache.org/jira/browse/SOLR-18665

Follow-up to #5358. Its readiness wait polls https://localhost:<port>, so bin/solr start fails after 180s on TLS nodes that refuse that request (CATS SslTest failure on #5323).

  • Probe the node's solr.host.advertise instead of localhost, so SNI host check passes.

  • If the port listens but requests get no HTTP response (e.g. mTLS with client hostname verification), warn, wait 3s and treat the node as started.
  • Verified with all SslTest cases on bash, including the @AwaitsFix mTLS ones.

    Diff: 208 lines (+173 / -35) across 7 files Reviewer: janhoy Review duration: 9956m
    All Vouch review confidence checks passed
    Residual risk 0.12 = Change Risk (0.81) × (1 − Review Confidence (0.85)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.81 · 208 lines diff across 7 files
    0.81
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.93 · 5 substantive comment(s)
    0.93
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    84%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.320
    Self Review self_review
    0.140
    Sensitive Paths sensitive_paths
    0.081
    Real PR Conversation Timeline
    11 items
    github-actions[bot] github-actions[bot] commented on Nov 20, 2026 09:21 UTC
    Bot

    Automated PR readiness judgements (LLM-generated; may be wrong; not updated on later pushes).

  • ✅ Jira issue in title: already present

  • ⚠️ Changelog — missing (suggest type: fixed): The change fixes a bug where &#96;bin&#47;​solr start&#96; would fail with a timeout on TLS nodes because the readiness check polled &#96;localhost&#96; instead of the advertised host&#44; and it adds a fallback for mTLS scenarios where the host cannot connect&#46;​

  • ✅ Reference Guide update: not needed <!-- The change modifies internal CLI behavior for the &#96;solr start&#96; command&#39;s readiness wait logic and does not introduce new user&#45;facing configuration parameters&#44; API endpoints&#44; or documented behaviors that require Reference Guide updates&#46;​ -->

  • ✅ Upgrade notes: not needed <!-- The change is a bug fix that improves the reliability of the &#96;solr start&#96; command for TLS setups and does not remove or rename any public APIs&#44; parameters&#44; or configuration elements&#46;​ -->

  • ✅ Tests: included <!-- The PR modifies non&#45;trivial production logic in &#96;StatusTool&#46;​java&#96; and &#96;SolrProcessManager&#46;​java&#96; to handle TLS and mTLS readiness checks&#44; which warrants new or updated tests to verify the new behavior&#46;​ -->
  • <!-- Assessed commit 196f8e7bd912754731f42bf671c7c559ff041ddd -->

    Copilot Copilot commented on code on Nov 20, 2026 10:13 UTC
    Code Review
    solr/core/src/java/org/apache/solr/cli/StatusTool.java:1
    @@ -307,21 +313,61 @@ public void waitForSolrUpAndPrintStatus(String pidUrl) throws Exception {
     
       /**
        * Wait for Solr to come online and return true if it does, false otherwise. A node that rejects
    -   * the request as unauthenticated or unauthorized counts as online.
    +   * the request as unauthenticated or unauthorized counts as online. So does a node whose port
    +   * accepts connections but which this host cannot talk to, such as one requiring a client
    +   * certificate this host's name does not match; it is given {@link #UNREACHABLE_GRACE_MS} to
    +   * finish starting.
        *
        * @return true if Solr comes online, false otherwise
        */
       public boolean waitForSolrUp(String pidUrl) throws Exception {
    -    try {
    -      waitToSeeSolrUp(pidUrl, credentials, maxWaitSecs, TimeUnit.SECONDS);
    -      return true;
    -    } catch (TimeoutException timeout) {
    -      return false;
    -    } catch (Exception e) {
    -      if (CLIUtils.exceptionIsAuthRelated(e)) {
    +    return waitForSolrUp(pidUrl, maxWaitSecs);
    +  }
    +
    +  @SuppressWarnings("BusyWait")
    +  boolean waitForSolrUp(String pidUrl, long maxWaitSecs) throws Exception {
    +    long timeout = System.nanoTime() + TimeUnit.SECONDS.toNanos(maxWaitSecs);
    +    int unreachable = 0;
    +    while (System.nanoTime() < timeout) {
    +      try {
    +        getStatus(pidUrl, credentials);
             return true;
    +      } catch (Exception e) {
    +        if (CLIUtils.exceptionIsAuthRelated(e)) {
    +          return true;
    +        }
    +        Throwable rootCause = SolrException.getRootCause(e);
    +        boolean noHttpResponse =
    +            rootCause instanceof IOException || rootCause instanceof SolrServerException;
    +        if (noHttpResponse && isListening(pidUrl)) {
    +          if (++unreachable >= 2) {
    +            CLIO.err(
    +                "WARNING: Solr is listening at "
    +                    + pidUrl
    +                    + " but this host cannot connect to it ("
    +                    + rootCause
    +                    + "); assuming it has started.");
    +            Thread.sleep(UNREACHABLE_GRACE_MS);
    +            return true;
    +          }
    +        } else {
    +          unreachable = 0;
    +        }
           }
    -      throw e;
    +      Thread.sleep(2000L);
    +    }
    +    return false;
    +  }

    waitForSolrUp(pidUrl, maxWaitSecs) can exceed maxWaitSecs and still return true due to unconditional sleeps (2s polling sleep and 3s UNREACHABLE_GRACE_MS). With small maxWaitSecs values this violates the method’s implied contract (wait up to max, then return false if not up). Consider computing remaining time each loop and bounding sleeps to the remaining deadline; also ensure the 'unreachable => assume started' path only triggers if there is enough remaining time (or return based on the deadline rather than a fixed sleep).

    Copilot Copilot commented on code on Nov 20, 2026 10:13 UTC
    Code Review
    solr/core/src/java/org/apache/solr/cli/SolrProcessManager.java:1
    @@ -154,6 +157,15 @@ private Optional<Integer> parsePortFromProcess(ProcessHandle ph) {
         return portStr.isPresent() ? portStr.map(Integer::parseInt) : Optional.empty();
       }
     
    +  private String parseAdvertisedHostFromProcess(ProcessHandle ph) {
    +    return arguments(ph).stream()
    +        .filter(a -> a.startsWith("-Dsolr.host.advertise="))
    +        .map(a -> a.substring(a.indexOf('=') + 1))
    +        .filter(h -> !h.isBlank())
    +        .findFirst()
    +        .orElse("localhost");
    +  }

    The substring(a.indexOf('=') + 1) assumes an '=' is present. If an argument ever matches the startsWith filter unexpectedly (or the prefix changes), indexOf('=') could be -1, producing the full string as the 'host' (e.g., -Dsolr.host.advertise), which would later generate invalid URLs. Safer parsing would remove the known prefix via its length (or explicitly validate indexOf('=') >= 0 / contains('=')) before substring extraction.

    Copilot Copilot commented on code on Nov 20, 2026 10:13 UTC
    Code Review
    solr/core/src/java/org/apache/solr/cli/StatusTool.java:1
    @@ -307,21 +313,61 @@ public void waitForSolrUpAndPrintStatus(String pidUrl) throws Exception {
     
       /**
        * Wait for Solr to come online and return true if it does, false otherwise. A node that rejects
    -   * the request as unauthenticated or unauthorized counts as online.
    +   * the request as unauthenticated or unauthorized counts as online. So does a node whose port
    +   * accepts connections but which this host cannot talk to, such as one requiring a client
    +   * certificate this host's name does not match; it is given {@link #UNREACHABLE_GRACE_MS} to
    +   * finish starting.
        *
        * @return true if Solr comes online, false otherwise
        */
       public boolean waitForSolrUp(String pidUrl) throws Exception {
    -    try {
    -      waitToSeeSolrUp(pidUrl, credentials, maxWaitSecs, TimeUnit.SECONDS);
    -      return true;
    -    } catch (TimeoutException timeout) {
    -      return false;
    -    } catch (Exception e) {
    -      if (CLIUtils.exceptionIsAuthRelated(e)) {
    +    return waitForSolrUp(pidUrl, maxWaitSecs);
    +  }
    +
    +  @SuppressWarnings("BusyWait")
    +  boolean waitForSolrUp(String pidUrl, long maxWaitSecs) throws Exception {
    +    long timeout = System.nanoTime() + TimeUnit.SECONDS.toNanos(maxWaitSecs);
    +    int unreachable = 0;
    +    while (System.nanoTime() < timeout) {
    +      try {
    +        getStatus(pidUrl, credentials);
             return true;
    +      } catch (Exception e) {
    +        if (CLIUtils.exceptionIsAuthRelated(e)) {
    +          return true;
    +        }
    +        Throwable rootCause = SolrException.getRootCause(e);
    +        boolean noHttpResponse =
    +            rootCause instanceof IOException || rootCause instanceof SolrServerException;
    +        if (noHttpResponse && isListening(pidUrl)) {

    This broad catch (Exception e) causes all non-auth exceptions to be retried until timeout, which can mask non-transient errors (e.g., malformed URL/URI parsing errors, misconfiguration) and turn them into a silent false return. Consider rethrowing immediately for clearly non-retryable exceptions (or only retrying for network/IO-category failures) so genuine configuration/usage errors fail fast instead of timing out.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 20, 2026 10:13 UTC
    Reviewer

    [!WARNING]

    Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

    <!-- ccr-overview-v2 -->

    Copilot review overview

    <details open>
    <summary><strong>3 open issues</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> waitForSolrUp(pidUrl, maxWaitSecs) can exceed maxWaitSecs and still return true due to… · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> The substring(a.indexOf('=') + 1) assumes an &#39;=&#39; is present. If an argument ever matches the… · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> This broad catch (Exception e) causes all non-auth exceptions to be retried until timeout,… · New

  • </details>

    <details>
    <summary><strong>What changed in this PR</strong></summary>

    Updates Solr CLI startup readiness checks to work correctly with TLS/SNI and certain mTLS setups by probing the node’s advertised host instead of localhost, and by treating “listening but unreachable” as started after a short grace period.

    Changes:

  • Add/adjust readiness waiting behavior to handle TLS host verification and “no HTTP response but port open” cases.

  • Extend SolrProcess to carry an advertised host and use it to build the local base URL.

  • Add tests covering “listening but unreachable” and “not listening” timeout behavior.
  • | File | Description |
    | ---- | ----------- |
    | solr/​core/​src/​java/​org/​apache/​solr/​cli/​StatusTool.java | Reworks waitForSolrUp polling logic; adds “listening but unreachable” handling and a grace wait. |
    | solr/​core/​src/​java/​org/​apache/​solr/​cli/​SolrProcessManager.java | Parses -Dsolr.host.advertise from process args; extends SolrProcess with host and updates URL building. |
    | solr/​core/​src/​test/​org/​apache/​solr/​cli/​StatusToolWaitTest.java | New tests for readiness wait when the port accepts connections but never returns HTTP, and for timeout when not listening. |
    | solr/​core/​src/​test/​org/​apache/​solr/​cli/​SolrProcessManagerTest.java | Updates tests to validate advertised host propagation and IPv6 host formatting. |
    | solr/​bin/​solr | Surfaces StatusTool WARNING lines from bin/solr start readiness check output. |
    </details>

    <sub>Review effort: Lite</sub>

    epugh epugh commented on Nov 20, 2026 11:16 UTC
    Contributor

    I actually gave up on SNI support and left it as a todo on the pr to secure zookeeper! I didn't realize we had this seperate address from Localhost and the code was getting messier. I will reevaluate based on this work.

    janhoy janhoy commented on code on Nov 22, 2026 00:01 UTC
    Code Review
    solr/core/src/java/org/apache/solr/cli/StatusTool.java:1
    @@ -307,21 +313,61 @@ public void waitForSolrUpAndPrintStatus(String pidUrl) throws Exception {
     
       /**
        * Wait for Solr to come online and return true if it does, false otherwise. A node that rejects
    -   * the request as unauthenticated or unauthorized counts as online.
    +   * the request as unauthenticated or unauthorized counts as online. So does a node whose port
    +   * accepts connections but which this host cannot talk to, such as one requiring a client
    +   * certificate this host's name does not match; it is given {@link #UNREACHABLE_GRACE_MS} to
    +   * finish starting.
        *
        * @return true if Solr comes online, false otherwise
        */
       public boolean waitForSolrUp(String pidUrl) throws Exception {
    -    try {
    -      waitToSeeSolrUp(pidUrl, credentials, maxWaitSecs, TimeUnit.SECONDS);
    -      return true;
    -    } catch (TimeoutException timeout) {
    -      return false;
    -    } catch (Exception e) {
    -      if (CLIUtils.exceptionIsAuthRelated(e)) {
    +    return waitForSolrUp(pidUrl, maxWaitSecs);
    +  }
    +
    +  @SuppressWarnings("BusyWait")
    +  boolean waitForSolrUp(String pidUrl, long maxWaitSecs) throws Exception {
    +    long timeout = System.nanoTime() + TimeUnit.SECONDS.toNanos(maxWaitSecs);
    +    int unreachable = 0;
    +    while (System.nanoTime() < timeout) {
    +      try {
    +        getStatus(pidUrl, credentials);
             return true;
    +      } catch (Exception e) {
    +        if (CLIUtils.exceptionIsAuthRelated(e)) {
    +          return true;
    +        }
    +        Throwable rootCause = SolrException.getRootCause(e);
    +        boolean noHttpResponse =
    +            rootCause instanceof IOException || rootCause instanceof SolrServerException;
    +        if (noHttpResponse && isListening(pidUrl)) {
    +          if (++unreachable >= 2) {
    +            CLIO.err(
    +                "WARNING: Solr is listening at "
    +                    + pidUrl
    +                    + " but this host cannot connect to it ("
    +                    + rootCause
    +                    + "); assuming it has started.");
    +            Thread.sleep(UNREACHABLE_GRACE_MS);
    +            return true;
    +          }
    +        } else {
    +          unreachable = 0;
    +        }
           }
    -      throw e;
    +      Thread.sleep(2000L);
    +    }
    +    return false;
    +  }

    The overshoot is bounded to one poll interval plus the grace period, and the grace only applies once the port was seen listening before the deadline, so returning true there is intended.

    janhoy janhoy commented on code on Nov 22, 2026 00:01 UTC
    Code Review
    solr/core/src/java/org/apache/solr/cli/StatusTool.java:1
    @@ -307,21 +313,61 @@ public void waitForSolrUpAndPrintStatus(String pidUrl) throws Exception {
     
       /**
        * Wait for Solr to come online and return true if it does, false otherwise. A node that rejects
    -   * the request as unauthenticated or unauthorized counts as online.
    +   * the request as unauthenticated or unauthorized counts as online. So does a node whose port
    +   * accepts connections but which this host cannot talk to, such as one requiring a client
    +   * certificate this host's name does not match; it is given {@link #UNREACHABLE_GRACE_MS} to
    +   * finish starting.
        *
        * @return true if Solr comes online, false otherwise
        */
       public boolean waitForSolrUp(String pidUrl) throws Exception {
    -    try {
    -      waitToSeeSolrUp(pidUrl, credentials, maxWaitSecs, TimeUnit.SECONDS);
    -      return true;
    -    } catch (TimeoutException timeout) {
    -      return false;
    -    } catch (Exception e) {
    -      if (CLIUtils.exceptionIsAuthRelated(e)) {
    +    return waitForSolrUp(pidUrl, maxWaitSecs);
    +  }
    +
    +  @SuppressWarnings("BusyWait")
    +  boolean waitForSolrUp(String pidUrl, long maxWaitSecs) throws Exception {
    +    long timeout = System.nanoTime() + TimeUnit.SECONDS.toNanos(maxWaitSecs);
    +    int unreachable = 0;
    +    while (System.nanoTime() < timeout) {
    +      try {
    +        getStatus(pidUrl, credentials);
             return true;
    +      } catch (Exception e) {
    +        if (CLIUtils.exceptionIsAuthRelated(e)) {
    +          return true;
    +        }
    +        Throwable rootCause = SolrException.getRootCause(e);
    +        boolean noHttpResponse =
    +            rootCause instanceof IOException || rootCause instanceof SolrServerException;
    +        if (noHttpResponse && isListening(pidUrl)) {

    This keeps the retry-on-any-non-auth-error behaviour of the existing waitToSeeSolrUp; during startup SolrJ's error types don't separate transient from permanent reliably enough to fail fast safely.

    janhoy janhoy commented on Nov 25, 2026 11:23 UTC
    Author

    I have put both this and #4710 into Draft mode and backtrack a bit. Moving the readiness checks into Java seemed as a good idea in the beginning, as CMD had been doing it for a while. But then the TLS issue complicates things and adds quite a lot of intricate code to Process Manager, which I believe comes with a smell.

    So I'm pausing this for a while, which unfortunately leaves things in a state where the startup is not correct when using TLS.

    Trying a different approach in a new PR, where I combine this and #4710 (SOLR-18336) into one PR since they are overlapping, and keeping more of the logic in bin/solr[.cmd]. Please see #5389 for the new, simpler, slimmer attempt

    epugh epugh commented on Nov 25, 2026 14:02 UTC
    Contributor

    Double points for moving back to DRAFT. Sometimes it just doesn't work!

    Reviewers
    Assignees
    janhoy janhoy
    Labels
    risk: low confidence: 84.9% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 80.9% (HIGH) · Higher = larger blast radius
    80.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 84.9% · Lower = rushed or shallow review
    84.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 12.2% · Safe to merge
    12.2%
    Repository