Avoid doNotifyQueueEmpty() race conditions for Redis
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 10 Nov 2015 22:34:24 +0000 (14:34 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 10 Nov 2015 22:34:24 +0000 (14:34 -0800)
Previously, races could cause queues to be seen as empty
and ignored when they actually have jobs in them.

Change-Id: I6cdf5c1fbd33c9ed7982e5d2d494974b1d7e09fd

includes/jobqueue/aggregator/JobQueueAggregatorRedis.php

index 6c49646..f8a0040 100644 (file)
@@ -59,7 +59,11 @@ class JobQueueAggregatorRedis extends JobQueueAggregator {
                        return false;
                }
                try {
-                       $conn->hDel( $this->getReadyQueueKey(), $this->encQueueName( $type, $wiki ) );
+                       // Make sure doNotifyQueueNonEmpty() takes precedence to avoid races
+                       $conn->watch( $this->getReadyQueueKey() );
+                       $conn->multi()
+                               ->hDel( $this->getReadyQueueKey(), $this->encQueueName( $type, $wiki ) )
+                               ->exec();
 
                        return true;
                } catch ( RedisException $e ) {