From cd58ffbaf58d5676b7405cf17c0dc32c51b3da2c Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 16 Jan 2018 17:58:59 +0100 Subject: [PATCH] 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 --- includes/libs/rdbms/loadbalancer/LoadBalancer.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 { -- 2.20.1