Skip to content

SOLR-18336: bin/solr.cmd start should wait only for the started Solr instance - #4710

Open
janhoy wants to merge 6 commits into
apache:mainfrom
janhoy:fix-windows-start-wait-all-pids
Open

janhoy wants to merge 6 commits into
apache:mainfrom
janhoy:fix-windows-start-wait-all-pids

Conversation

@janhoy

@janhoy janhoy commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes https://issues.apache.org/jira/browse/SOLR-18336

The Windows start script now passes -p <port> to SolrCLI status, so the start wait targets only the newly started instance instead of every PID file found.

The status tool resolves the instance's URL from the running process's own command line: it prefers -Dsolr.host.advertise when set, falls back to a non-loopback -Dsolr.host.bind, and maps loopback/wildcard binds to localhost. Since the process may not be visible in the process table immediately after launch, the tool re-scans until the --max-wait-secs deadline instead of failing on the first miss.

This gives the same behavior as 9.x, which built --solr-url from SOLR_HOST (the advertised host) when set, else localhost: the wait connects to the advertised name — so SSL hostname verification against certificates issued for that name keeps working — and non-loopback binds (SOLR_HOST_BIND=10.0.x.x) no longer fail with a localhost connection error. As a bonus, bin/solr status now prints reachable URLs for such nodes too.

PS: The Linux start script does not use SolrCLI for waiting for Solr, thus it was never affected. With these hardenings, we are perhaps soon ready to migrate the linux start script over to StatusTool as well.

@janhoy
janhoy marked this pull request as draft August 4, 2026 23:25
@epugh

epugh commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Seems reasonable.. and I guess a bats test woudn't have caught this since it's windows only...

@janhoy janhoy changed the title Fix bin/solr.cmd start waiting for all running Solr instances SOLR-18336: bin/solr.cmd start should wait only for the started Solr instance Aug 5, 2026
@janhoy
janhoy marked this pull request as ready for review August 5, 2026 15:11
@github-actions github-actions Bot added the tests label Aug 5, 2026
@janhoy
janhoy requested a review from epugh August 5, 2026 15:17

@epugh epugh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks great. I think my one problem is that we're solving windows issues in our java code, but we don't have great testing in our windows path... I'd love, if we believe this is viable code, and it appears to be, to apply this to the linux path as well, that way if bugs crop up, the theory is we'll see and fix them tjhat much sooner. For example, we could use a bats test if we wanted...

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

This PR has had no activity for 60 days and is now labeled as stale. Any new activity will remove the stale label. To attract more reviewers, please tag people who might be familiar with the code area and/or notify the dev@solr.apache.org mailing list. To exempt this PR from being marked as stale, make it a draft PR or add the label "exempt-stale". If left unattended, this PR will be closed after another 60 days of inactivity. Thank you for your contribution!

@github-actions github-actions Bot added the stale PR not updated in 60 days label Oct 6, 2026
@janhoy
janhoy requested a balanced review from Copilot October 6, 2026 01:18

This comment was marked as resolved.

@github-actions github-actions Bot removed the stale PR not updated in 60 days label Oct 7, 2026
@janhoy

janhoy commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Would be sad for this to die...

@janhoy
janhoy marked this pull request as draft November 10, 2026 22:01
…instance

On Windows, 'solr.cmd start' invoked 'status --max-wait-secs' without
identifying the instance just started, causing the status tool to scan the
PID directory and wait for every running Solr instance. Pass the port so
only the newly started instance is waited for, matching bin/solr on Linux.
The status tool resolves the URL scheme (http/https) from the running
process itself.

The local URL for a process now prefers -Dsolr.host.advertise when set and
falls back to the bind host parsed from the process command line. With
SOLR_HOST_BIND set to a non-loopback address Jetty does not listen on
localhost, so probing a hardcoded localhost could never reach the instance.
Wildcard and loopback bind addresses still map to localhost, preserving
existing URLs for default installs and keeping SSL hostname verification
working with certificates issued for localhost.

The -p wait re-scans for the process until the deadline instead of failing
if the newly started process is not yet visible. Sysprop parsing is
collapsed into one helper, dropping the unreachable -Dsolr.jetty.host
fallback (10.x scripts always translate the deprecated name to
solr.host.bind before launch), and the process wait loop moves into
SolrProcessManager.waitForProcessOnPort, reusing the TimeOut utility.
… args

On Windows the process arguments are recovered by splitting the raw
command line, so quotes that the OS would have removed may still
surround an argument or its value. Strip one surrounding quote pair,
and match the -D prefix at the start of the argument rather than
anywhere in it.
The JVM uses the last occurrence of a -D property, and bin/solr appends
user SOLR_OPTS after the properties it generates itself. Picking the
first match therefore ignored a user override of e.g. the advertised
host.
Rewriting an advertised 127.0.0.1 or ::1 to localhost could break TLS
hostname verification when the certificate covers the advertised
address but not localhost. Loopback is now only normalized in the
bind-host fallback, where no name is advertised. A wildcard advertised
address is not connectable, so it falls through to the bind host.
…wait

Waiting for the process to appear and then waiting for it to answer
HTTP each used the full --max-wait-secs, so a slow process scan could
nearly double the time the start script waits. Both now draw from one
deadline, and an exhausted budget is reported as a timeout.
The option is declared twice, once per parser, and only the commons-cli
twin was reworded. Regenerated the ref guide page, which is built from the
picocli annotations.
@janhoy
janhoy force-pushed the fix-windows-start-wait-all-pids branch from 8ab53f0 to 1d81010 Compare November 12, 2026 13:05
@janhoy

janhoy commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Rebased on current main (2b0eb4962ba) and removed the temporary .github/workflows/windows-solr-cmd-test.yml, which was only scaffolding for trying this out on Windows CI.

Self-review turned up one thing the rebase made stale: --port is now declared twice in StatusTool, once per parser, and only the commons-cli twin carried the reworded description. Aligned the picocli annotation and regenerated pages/cli/solr-status.adoc from it. Nothing else — no leftover debugging, and the changelog entry still describes what the patch does.

Verified: SolrProcessManagerTest (11 tests), StatusToolTest + StatusToolPicocliTest, and :solr:core:check -x test all pass locally.

Worth noting for merge: this bug now has a second, independent reproduction. The new cross-platform CLI test suite (SOLR-18642, #5323) hits the same hardcoded-localhost probe through Jetty's SNI host check rather than through a non-loopback bind, and its test is marked @AwaitsFix against SOLR-18336 until this lands. Evidence is on SOLR-18336.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Nov 12, 2026
@janhoy
janhoy marked this pull request as ready for review November 12, 2026 13:08
@github-actions

Copy link
Copy Markdown

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

  • ✅ Jira issue in title: already present
  • ✅ Changelog: type: fixed
  • ⚠️ Reference Guide update — probably not needed (confidence: medium): The change modifies internal behavior of the CLI status tool and the Windows start script to correctly target the specific instance and resolve the correct host, but does not introduce new configuration options, parameters, or user-facing API changes that require Reference Guide documentation.​
  • ✅ Upgrade notes: not needed
  • ✅ Tests: included

@janhoy
janhoy requested review from epugh and malliaridis November 12, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cat:cli documentation Improvements or additions to documentation start-scripts tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants