SOLR-18665: Make bin/solr start wait for readiness #5358
Automated PR readiness judgements (LLM-generated; may be wrong; not updated on later pushes).
<!-- Assessed commit 771634b674ea59fd1052064e7c2543eb872d0901 -->
<!-- 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:
SolrCLI status --max-wait-secs for readiness while retaining the spinner and startup output.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>
I don't know if being more specific about what "ready" means is worth mentioning?
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?
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!
The solr assert --started calls the same StatusTool.waitToSeeSolrUp as the status tool, but keeping it identical to what solr.cmd uses.
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;
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.
🤖 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 ACLstest_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.
- :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.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
@dsmiley Have you seen See #5368 ?
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.
epugh
janhoy
🤖 AI-assisted, reviewed by Jan
bin/solr startnow waits withSolrCLI status --max-wait-secs, the real readiness check, instead of polling for a TCP listener that Jetty 12 opens before the webapp loads. Spinner, theStarted Solr server on port P (pid=N). Happy searching!line and thetail -30 solr.logon timeout are unchanged.wait, where the old timeout branchexited only the subshell.solr restartandsolr start -e <example>go through the same wait and inherit both fixes;solr.cmdalready checked its exit code and needs no change.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 toyum install lsoffirst, 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.solr restartandsolr start -e techproducts --no-promptstill work end to end;tidy, shellcheck,check -x testand thetest_start_solr.batsandtest_zk.batssuites are green on both the picocli and commons-cli paths.https://issues.apache.org/jira/browse/SOLR-18665