janhoy commented on code in PR #5368:
URL: https://github.com/apache/solr/pull/5368#discussion_r4655639338
##########
solr/core/src/java/org/apache/solr/cli/StatusTool.java:
##########
@@ -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;
+ }
Review Comment:
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.
##########
solr/core/src/java/org/apache/solr/cli/StatusTool.java:
##########
@@ -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)) {
Review Comment:
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]