Skip to content
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

Merged
merged 8 commits into from
Oct 19, 2017
Merged

Conversation

andrerom
Copy link
Contributor

@andrerom andrerom commented Oct 17, 2017

issue: https://jira.ez.no/browse/EZP-28088

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:

  • Logger

@ezsystems ezsystems deleted a comment from ezrobot Oct 17, 2017

// 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);
Copy link
Member

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);
}

Copy link
Contributor Author

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?

Copy link
Member

@adamwojs adamwojs Oct 17, 2017

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.

@ezsystems ezsystems deleted a comment from ezrobot Oct 18, 2017
@ezsystems ezsystems deleted a comment from ezrobot Oct 18, 2017
@andrerom andrerom force-pushed the EZP-28088 branch 2 times, most recently from 832052c to 26a6570 Compare October 18, 2017 12:46
@andrerom
Copy link
Contributor Author

@adamwojs Better?

@andrerom andrerom merged commit aab1f64 into 1.4 Oct 19, 2017
@andrerom andrerom deleted the EZP-28088 branch October 19, 2017 11:34
andrerom added a commit that referenced this pull request Nov 3, 2017
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants