-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EZP-28088: Re-try connections when trying to reach Solr #109
Conversation
lib/Gateway/HttpClient/Stream.php
Outdated
|
||
// Wait for 100ms before we retry | ||
// Timeout is 10s, so time spent in worst case is 50.5s, which is less then default_socket_timeout (60s) | ||
usleep(100000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract hardcoded values to const would make the code more self-explanatory and easier to configure IMHO.
// Connection timeout in ms
const CONNECTION_TIMEOUT = 10000;
// Number of connection attempts
const CONNECTION_RETRY_TIMES = 5;
// Connection retry in ms. Timeout is 10s, so time spent in worst case is 50.5s,
// which is less then default_socket_timeout (60s)
const CONNECTION_RETRY_DELAY = 100;
// ...
for ($i = 0; $i < self::CONNECTION_RETRY_TIMES; $i++) {
$responseMessage = $this->requestStream($method, $endpoint, $path, $message)
if (responseMessage !== null) {
return $responseMessage;
}
// Wait before we retry
usleep(1000 * self::CONNECTION_RETRY_DELAY);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, but impossible yet to set them as private const, so might be better with properties?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, properties will be better.
832052c
to
26a6570
Compare
@adamwojs Better? |
* EZP-28088: Re-try connections when trying to reach Solr * CS * Use properties and allow setting them via constructor * CS * CS * Add error logging of failed connection * Change back to timeput of 10s now that tests should pass * PHPDOC [skip ci] (cherry picked from commit aab1f64)
Note: This does not handle HTTP error codes returned, as code uses
ignore_errors
, however afaik what is relevant here is cases where we don't reach Solr (network errors/dns/..). But if anyone see any other cases that would be relevant here please share :)Also open question is if Solr would sometimes needs more time than 10s for handling calls, so might be timeout is too low here.
Todo: