@@ -327,13 +327,25 @@ public function delete($url, array $customHeaders = [], $data = '')
327
327
*/
328
328
private function handleFailover ($ cb )
329
329
{
330
+ $ start = microtime (true );
330
331
if (!$ this ->_options ->haveMultipleEndpoints ()) {
331
- // the simple case: no failover
332
- return $ cb ();
332
+ // the simple case: just one server
333
+ while (true ) {
334
+ try {
335
+ return $ cb ();
336
+ } catch (FailoverException $ e ) {
337
+ if (microtime (true ) - $ start >= $ this ->_options [ConnectionOptions::OPTION_FAILOVER_TIMEOUT ]) {
338
+ // timeout reached, we will abort now
339
+ $ this ->notify ('servers not reachable after timeout ' );
340
+ throw $ e ;
341
+ }
342
+ // continue because we have not yet reached the timeout
343
+ usleep (20 * 1000 );
344
+ }
345
+ }
333
346
}
334
347
335
348
// here we need to try it with failover
336
- $ start = microtime (true );
337
349
$ tried = [];
338
350
$ notReachable = [];
339
351
while (true ) {
@@ -643,7 +655,6 @@ public function parseResponse(HttpResponse $response)
643
655
644
656
if ($ httpCode < 200 || $ httpCode >= 400 ) {
645
657
// failure on server
646
-
647
658
$ body = $ response ->getBody ();
648
659
if ($ body !== '' ) {
649
660
// check if we can find details in the response body
@@ -687,6 +698,13 @@ public function parseResponse(HttpResponse $response)
687
698
throw $ exception ;
688
699
}
689
700
}
701
+
702
+ // check if server has responded with any other 503 response not handled above
703
+ if ($ httpCode === 503 ) {
704
+ // generic service unavailable response
705
+ $ exception = new FailoverException ('service unavailable ' , 503 );
706
+ throw $ exception ;
707
+ }
690
708
691
709
// no details found, throw normal exception
692
710
throw new ServerException ($ response ->getResult (), $ httpCode );
0 commit comments