When clearing the cache, I started getting messages like the following. They just kept repeating, even if I let it run for hours.

$ drush cc all
WD rules: Cache rebuild lock hit: rules_event_whitelist                                                                                     [warning]
WD rules: Cache rebuild lock hit: rules_event_whitelist                                                                                     [warning]
WD rules: Cache rebuild lock hit: rules_event_whitelist                                                                                     [warning]
...

The problem started when I replaced my dev site's database with a different (newer) database dump. The site where the database dump came from does not have this problem.

I checked if this was covered by related issues:

Workaround #1: Downgrade to Rules 7.x-2.7. This enables the cache to clear. (Upgrading back to Rules 7.x-2.9 brings the problem back.)

Workaround #2: Temporarily comment out the following code in rules.module, function rules_get_cache:

      while (!lock_acquire(__FUNCTION__ . $cid . $cid_suffix, 60)) {
        rules_log('Cache rebuild lock hit: !cid', array('!cid' => $cid), RulesLog::WARN);
        // Now wait until the lock is released.
        lock_wait(__FUNCTION__ . $cid . $cid_suffix, 10);
        // If the lock is released it's likely the cache was rebuild. Thus check
        // again if we can fetch it from the persistent cache.
        if ($get = cache_get($cid . $cid_suffix, 'cache_rules')) {
          $cache[$cid] = $get->data;
          return $cache[$cid];
        }
      }

Somehow my system got into a state where the above code loops forever. It looks like this code is repeatedly checking if rules_event_whitelist is cached, and if not, waiting for some other concurrent code to cache it? I guess nothing else is coming along and caching it. Later in the function, the call to RulesEventSet::rebuildEventCache() caches it.

Edit: For Workaround #2, if you comment out the code and clear the cache, then uncomment it and clear the cache, that works. But the problem soon comes back.

Comments

jlstrecker created an issue. See original summary.

jlstrecker’s picture

Issue summary: View changes
steveworley’s picture

Hey @jlstrecker, I noticed similar behaviour with a site I was working on. It's looks as though there is a time where the cache never gets built in the concurrent request (ie. if the process fails). Lock acquire will continue to extend the lock each time the loop fails so it seemed like my cache could never be built and a process would end up hanging forever.

I created a patch which seemed to help alleviate the issue for me. It will allow you to tune Rules stampede protection per site (you can configure the lock lease time via settings) and it will now only wait for one iteration of the lock as opposed to looping for small durations to see if the lock has been released.

steveworley’s picture

StatusFileSize
new1.72 KB
steveworley’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: 2715513-lock-protection-loop-3.patch, failed testing.

mcdruid’s picture

Status: Needs work » Closed (duplicate)

Closing as a duplicate of #2406863: stampede protection should be flexible ("Cache rebuild lock hit" watchdog message) which has more background on this issue.

I'm about to post a patch in that issue which is similar to steveworley's in #4 here.