From 8c781f92bad810e55f6b62c06b619913cfe81d32 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sun, 29 Dec 2013 13:44:33 -0800 Subject: [PATCH] Fixed locking in JobQueueAggregatorRedis * The old code would still bump the lock TTL on failure, so if processes kept trying to acquire it and the one that had it crashed, nothing would ever do anything. Change-Id: If3fe7b75364204f399fb4caf8bd39204ab51b353 --- includes/job/aggregator/JobQueueAggregatorRedis.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/job/aggregator/JobQueueAggregatorRedis.php b/includes/job/aggregator/JobQueueAggregatorRedis.php index 057a5878e8..c654933c25 100644 --- a/includes/job/aggregator/JobQueueAggregatorRedis.php +++ b/includes/job/aggregator/JobQueueAggregatorRedis.php @@ -104,10 +104,12 @@ class JobQueueAggregatorRedis extends JobQueueAggregator { } } else { // cache miss // Avoid duplicated effort + $rand = wfRandomString( 32 ); $conn->multi( Redis::MULTI ); - $conn->setnx( $this->getReadyQueueKey() . ":lock", 1 ); - $conn->expire( $this->getReadyQueueKey() . ":lock", 3600 ); + $conn->setex( "{$rand}:lock", 3600, 1 ); + $conn->renamenx( "{$rand}:lock", $this->getReadyQueueKey() . ":lock" ); if ( $conn->exec() !== array( true, true ) ) { // lock + $conn->delete( "{$rand}:lock" ); return array(); // already in progress } -- 2.20.1