From: Aaron Schulz Date: Tue, 16 Jan 2018 16:58:59 +0000 (+0100) Subject: rdbms: make LoadBalancer::waitForAll() better respect the timeout X-Git-Tag: 1.31.0-rc.0~823^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/voir.php?a=commitdiff_plain;h=cd58ffbaf58d5676b7405cf17c0dc32c51b3da2c;p=lhc%2Fweb%2Fwiklou.git rdbms: make LoadBalancer::waitForAll() better respect the timeout If several replicas (or even all) had replication stuck, then the timeout would happen for each server, one after another. Change-Id: Id5431360b9cde7e5dc0115a1f41b9903003f47c4 --- diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php b/includes/libs/rdbms/loadbalancer/LoadBalancer.php index e80b9520e5..9c5a1072be 100644 --- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php @@ -518,6 +518,8 @@ class LoadBalancer implements ILoadBalancer { } public function waitForAll( $pos, $timeout = null ) { + $timeout = $timeout ?: $this->mWaitTimeout; + $oldPos = $this->mWaitForPos; try { $this->mWaitForPos = $pos; @@ -526,7 +528,12 @@ class LoadBalancer implements ILoadBalancer { $ok = true; for ( $i = 1; $i < $serverCount; $i++ ) { if ( $this->mLoads[$i] > 0 ) { - $ok = $this->doWait( $i, true, $timeout ) && $ok; + $start = microtime( true ); + $ok = $this->doWait( $i, true, max( 1, (int)$timeout ) ) && $ok; + $timeout -= ( microtime( true ) - $start ); + if ( $timeout <= 0 ) { + break; // timeout reached + } } } } finally {