← Back to Pull requests

SOLR-18665: Make bin/solr start wait for readiness #5358

Merged
janhoy merged 7 files (91 lines) on Nov 18, 2026 15:16 UTC
View on GitHub
janhoy janhoy commented on Nov 17, 2026 10:19 UTC
Author

🤖 AI-assisted, reviewed by Jan

  • bin/solr start now waits with SolrCLI status --max-wait-secs, the real readiness check, instead of polling for a TCP listener that Jetty 12 opens before the webapp loads. Spinner, the Started Solr server on port P (pid=N). Happy searching! line and the tail -30 solr.log on timeout are unchanged.

  • A start that never completes now exits non-zero: the background wait's status is collected with wait, where the old timeout branch exited only the subshell. solr restart and solr start -e <example> go through the same wait and inherit both fixes; solr.cmd already checked its exit code and needs no change.

  • That was the last use of lsof, so it goes, along with its "no lsof" fallback that slept 10 seconds and declared success. With it go the references it left behind: the installer no longer recommends installing lsof "for more stable start/stop", the ref guide no longer tells Red Hat users to yum install lsof first, and the cygwin refusal no longer lists it as a reason. The Docker image stops shipping it too, since nothing in Solr calls it and it is not tooling we support; an image that needs it can add it in a downstream layer.

  • Validated against a built distribution, 5 runs per case. On a busy CPU the stock script returned success while the embedded ZooKeeper port was not yet listening in 5 of 5 runs; with the fix the node was ready in 5 of 5. Starting on an already-occupied port used to exit 0 in 1.1 s announcing a pid, and now exits 1. Idle, the node was still 0.34–0.60 s short of answering HTTP when the old wait returned, against nothing measurable after. The cost is about a second of start time when idle, which is the wait being honest. solr restart and solr start -e techproducts --no-prompt still work end to end; tidy, shellcheck, check -x test and the test_start_solr.bats and test_zk.bats suites are green on both the picocli and commons-cli paths.
  • https://issues.apache.org/jira/browse/SOLR-18665

    Diff: 91 lines (+53 / -38) across 7 files Reviewer: epugh Review duration: 1736m
    All Vouch review confidence checks passed
    Residual risk 0.03 = Change Risk (0.39) × (1 − Review Confidence (0.92)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 91 lines diff across 7 files
    0.39
    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%
    92%
    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.271
    Real PR Conversation Timeline
    11 items
    github-actions[bot] github-actions[bot] commented on Nov 17, 2026 10:25 UTC
    Bot

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

  • ✅ Jira issue in title: already present

  • ✅ Changelog: type: fixed <!-- The change fixes a race condition where &#96;bin&#47;​solr start&#96; would return success before the node was actually ready&#44; and ensures the command exits non&#45;zero on failure&#44; which are user&#45;visible bug fixes&#46;​ -->

  • ✅ Reference Guide update: included <!-- The PR removes references to &#96;lsof&#96; from the documentation &#40;specifically the recommendation to install it for stable start&#47;​stop&#41;&#44; so the Reference Guide needs to be updated to reflect that &#96;lsof&#96; is no longer required or recommended&#46;​ -->

  • ✅ Upgrade notes: not needed <!-- The change is a bug fix that improves reliability and does not remove or rename any public API&#44; configuration&#44; or command&#45;line interface elements that would require user action during an upgrade&#46;​ -->

  • ✅ Tests: not needed <!-- The changes are confined to shell scripts &#40;&#96;bin&#47;​solr&#96;&#44; &#96;install&#95;solr&#95;service&#46;​sh&#96;&#41; and the Dockerfile&#44; which fall under build&#47;​CI&#47;​developer tooling and do not require new unit tests&#46;​ -->
  • <!-- Assessed commit 771634b674ea59fd1052064e7c2543eb872d0901 -->

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

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

    🔵 Needs a closer look

    The startup readiness check can reject healthy JWT/HTTPS nodes and exceed its configured wait, while misleading failure diagnostics and missing regression coverage compound these issues.

    No open issues 🎉

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

    This PR changes Unix Solr startup to wait for application readiness rather than an open TCP port, preventing commands from racing startup.

    Changes:

  • Uses SolrCLI status --max-wait-secs for readiness while retaining the spinner and startup output.

  • Propagates readiness-check failures as nonzero startup exits.

  • Removes the unused lsof dependency and related installation guidance.
  • | File | Description |
    | ---- | ----------- |
    | solr/​solr-ref-guide/​modules/​deployment-guide/​pages/​taking-solr-to-production.adoc | Removes the Red Hat lsof prerequisite. |
    | solr/​docker/​templates/​Dockerfile.body.template | Removes lsof from image packages. |
    | solr/​bin/​solr | Adds readiness checking, propagates failures, and removes lsof usage. |
    | solr/​bin/​install_solr_service.sh | Removes the recommendation to install lsof. |
    | changelog/​unreleased/​SOLR-18665-start-readiness.yml | Documents readiness waiting and nonzero startup failure exits. |
    </details>

    <sub>Review effort: Balanced</sub>

    epugh epugh commented on code on Nov 17, 2026 11:33 UTC
    Code Review
    changelog/unreleased/SOLR-18665-start-readiness.yml:1
    @@ -0,0 +1,13 @@
    +# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
    +
    +title: >
    +  `bin/solr start` now waits for the node to be ready, instead of for its port to be listening, so a

    I don't know if being more specific about what "ready" means is worth mentioning?

    epugh epugh commented on code on Nov 17, 2026 11:35 UTC
    Code Review
    solr/bin/solr:1
    @@ -513,6 +513,21 @@ function run_tool() {
       return $?
     } # end run_tool function
     
    +# Wait for the node on $SOLR_PORT_LISTEN to answer, as bin/solr.cmd does. Jetty binds its
    +# connectors before the Solr webapp starts, so a listening port is no proof of readiness.
    +function wait_for_solr_ready() {
    +  local status_output
    +  if status_output=$(run_tool status -p "$SOLR_PORT_LISTEN" --max-wait-secs "$SOLR_START_WAIT" 2>&1); then

    just out of curisotiy, would using the assert tool have been useful here? Also, does assert use _timeout_ and this tool uses _max-wait-secs_? Should those two parameters align?

    epugh epugh approved these changes on Nov 17, 2026 11:37 UTC
    Approved Reviewer

    LGTM. I was bit by this when I built the TUI, that the bin/solr start returned, but they can't actually hit the endpoint. In that case I used the bin/solr assert to wait till it was fully available.

    Also nice to see a simplifying PR that removes lines of code! Especially non java code!

    janhoy janhoy commented on code on Nov 18, 2026 14:41 UTC
    Code Review
    solr/bin/solr:1
    @@ -513,6 +513,21 @@ function run_tool() {
       return $?
     } # end run_tool function
     
    +# Wait for the node on $SOLR_PORT_LISTEN to answer, as bin/solr.cmd does. Jetty binds its
    +# connectors before the Solr webapp starts, so a listening port is no proof of readiness.
    +function wait_for_solr_ready() {
    +  local status_output
    +  if status_output=$(run_tool status -p "$SOLR_PORT_LISTEN" --max-wait-secs "$SOLR_START_WAIT" 2>&1); then

    The solr assert --started calls the same StatusTool.waitToSeeSolrUp as the status tool, but keeping it identical to what solr.cmd uses.

    janhoy janhoy commented on code on Nov 18, 2026 14:48 UTC
    Code Review
    changelog/unreleased/SOLR-18665-start-readiness.yml:1
    @@ -0,0 +1,13 @@
    +# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
    +
    +title: >
    +  `bin/solr start` now waits for the node to be ready, instead of for its port to be listening, so a

    For changelog audience I think this is sufficient.

    I was a bit surprised myself to find this bug. I thought port listening == ready. But I realize Jetty will open the port before all the web apps have done their initialization. So it could be we need an even better "ready" gate than what StatusTool uses. But it's a fracion of a second, so perhaps just adding the JVM startup time of the StatusTool call is enough to fix what you and I experienced? I asked Claude, who answered;

  • The status check calls /admin/info/system. Jetty only starts serving requests after the Solr webapp has finished starting. In the startup log, "Started ServerConnector" comes after the CoreContainer init lines.

  • So any answer at all means CoreContainer.load() has returned. By then solr.xml is parsed, the auth plugins are loaded, and in cloud mode the ZooKeeper connection is set up.
  • Recovery and heavy core initialization may not yet be ready but that would serve a 503 and a client would re-try. So I think we're good.

    dsmiley dsmiley commented on Nov 21, 2026 04:31 UTC
    Contributor

    🤖 Heads-up: this change appears to have broken the nightly Solr-TestIntegration-main job (BATS). Builds 733 and 734 fail the same 3 tests on two different agents; 731 (at 4890215acc8, just before this commit) passed. Build 732 never ran its tests because of an agent JAVA_HOME problem. Of the commits in that range, this is the only one that touches bin/solr start behavior. Until it's fixed, this may also hold up backports of this change and others, since the integration suite is red.

    Failing tests

  • test_secure_example.bats:39: secure example starts two HTTPS nodes with authentication and ZooKeeper ACLs

  • test_ssl.bats:122: use different hostname when not checking peer-name (solr restart failed)

  • test_ssl.bats:360: start solr with mTLS needed (solr start -z localhost:${ZK_PORT} -p ${SOLR3_PORT} failed)
  • Analysis

    start_solr used to wait only until lsof saw the port listening. It now runs status -p $SOLR_PORT_LISTEN --max-wait-secs $SOLR_START_WAIT, which needs a successful request to https://localhost:<port>/solr. waitForSolrUp only treats 401/403 as "up". Any other error is retried until the timeout, and then start returns 1.

  • test_ssl.bats:122 and :360: both tests deliberately start a node that the CLI client can't talk to.

  • - :122 sets -Dsolr.jetty.ssl.sni.host.check.enabled=true, so a request to localhost gets "Invalid SNI" (HTTP 400).
    - :360 sets SOLR_SSL_CLIENT_HOSTNAME_VERIFICATION=true. The test's own comment says "We can't check if the server has come up, because we can't connect to it".
    - In both cases the node does come up (the log shows cores loading), but start waits the full 180s and then fails.
  • test_secure_example.bats:39 (less certain): step 5 restarts node1 with ZK digest ACLs, and that restart failed after about 2s instead of waiting out the 15s timeout. The solr.log tail that was printed comes from the previous process's shutdown. That suggests status -p exited right away rather than polling. The likely path is processForPort() returning empty ("Could not find a running Solr on port …"), maybe because the new JVM wasn't visible yet. The runTool port branch exits 1 at that point without honoring --max-wait-secs. The real message is hidden because wait_for_solr_ready prints status_output only with --verbose.
  • Possible fixes
    1. In waitForSolrUp, treat any HTTP response from the server (e.g. Jetty's 400 for the SNI case) as "up", as 401/403 already are. A TLS rejection could arguably count too. The alternative is to change the two SSL tests to tolerate a failing start (run solr start …).
    2. With --max-wait-secs, make status -p keep polling for the process instead of exiting right away when none is found yet.
    3. Print status_output on failure regardless of --verbose, so CI logs show the cause.
    4. The CATS ports merged in #5323 (SslTest, SecureExampleTest) probably have the same expectations.

    Testing: run the BATS tests locally with ./gradlew iTest --tests test_ssl.bats and ./gradlew iTest --tests test_secure_example.bats, or run the CATS equivalents with ./gradlew -p solr/packaging catsTests --tests "*SslTest".

    🤖 Generated with Claude Code

    janhoy janhoy commented on Nov 21, 2026 07:49 UTC
    Author

    @dsmiley Have you seen See #5368 ?

    dsmiley dsmiley commented on Nov 21, 2026 14:10 UTC
    Contributor

    Okay; please backport this and that one (assuming it fixes this) when ready. I need my backport automation to defer to individuals (e.g. you) when the build breaks, rather than figuring out how to make the automated process somehow aware of how to handle non-standard situations.

    Reviewers
    Assignees
    janhoy janhoy
    Labels
    risk: low confidence: 92.4% reviewed
    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: 38.8% (MEDIUM) · Higher = larger blast radius
    38.8%
    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: 92.4% · Lower = rushed or shallow review
    92.4%
    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: 3.0% · Safe to merge
    3.0%
    Repository