From: Aaron Schulz Date: Wed, 15 Aug 2018 02:24:37 +0000 (-0700) Subject: rdbms: add domain sanity checks to LoadBalancer connection methods X-Git-Tag: 1.34.0-rc.0~3787^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/comptes/journal.php?a=commitdiff_plain;h=b416e166a3eba1dcfc2e912e37e443981d7f60ef;p=lhc%2Fweb%2Fwiklou.git rdbms: add domain sanity checks to LoadBalancer connection methods Bug: T193565 Change-Id: I94d905277e01b8e30ac3f6532ece07388bb20cce --- diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php b/includes/libs/rdbms/loadbalancer/LoadBalancer.php index d84ba65e3d..ff762b42cc 100644 --- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php @@ -28,6 +28,7 @@ use BagOStuff; use EmptyBagOStuff; use WANObjectCache; use ArrayUtils; +use UnexpectedValueException; use InvalidArgumentException; use RuntimeException; use Exception; @@ -952,6 +953,17 @@ class LoadBalancer implements ILoadBalancer { } } + // Final sanity check to make sure the right domain is selected + if ( + $conn instanceof IDatabase && + $this->localDomain->getDatabase() !== null && + $conn->getDomainID() !== $this->localDomain->getId() + ) { + throw new UnexpectedValueException( + "Got connection to '{$conn->getDomainID()}', " . + "but expected local domain ('{$this->localDomain}')." ); + } + return $conn; } @@ -1038,8 +1050,13 @@ class LoadBalancer implements ILoadBalancer { } } - // Increment reference count if ( $conn instanceof IDatabase ) { + // Final sanity check to make sure the right domain is selected + if ( $domainInstance->getDatabase() !== null && $conn->getDomainID() !== $domain ) { + throw new UnexpectedValueException( + "Got connection to '{$conn->getDomainID()}', but expected '$domain'." ); + } + // Increment reference count $refCount = $conn->getLBInfo( 'foreignPoolRefCount' ); $conn->setLBInfo( 'foreignPoolRefCount', $refCount + 1 ); }