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:
- Tried 'truncate cache_rules', as suggested on #2406863: stampede protection should be flexible ("Cache rebuild lock hit" watchdog message). Didn't help.
- Applied patches from #2650886: Reduce the likeliness of cache rebuilding locks and #2189645: Avoid full cache clear whenever a rules component or reaction rule is edited. Didn't help.
- The patch for #2190775: Misuse of variables table with rules_event_whitelist is already in 7.x-2.9.
- Tried Rules 7.x-2.x-dev. Didn't help. (The warning no longer prints because of #2406863: stampede protection should be flexible ("Cache rebuild lock hit" watchdog message), but it still gets stuck.)
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.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 2715513-lock-protection-loop-3.patch | 1.72 KB | steveworley |
Comments
Comment #2
jlstreckerComment #3
steveworley commentedHey @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.
Comment #4
steveworley commentedComment #5
steveworley commentedComment #7
mcdruid commentedClosing 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.