Follow-up to #251792: Implement a locking framework for long operations, we want to use locks to prevent block rehash from being performed by more than one request

Comments

dddave’s picture

What is the state of this in D7? Should this go against D8 or be closed?

nagba’s picture

Not sure about D8, block code seems to be very very different there. For the time being, the patch is for D7. I was playing with the idea of returning an empty array when the lock is taken instead of waiting, but then it would cause quite some complications because we would not be able to tell if we got a empty blocks because the theme does not have any, or because the lock wasnt free.

nagba’s picture

Status: Active » Needs review
nagba’s picture

this version will include less waiting

pwolanin’s picture

If the process waited, maybe it should just get the blocks, instead of rehashing again?

nagba’s picture

Good idea. Unfortunately the block data in the block table is not complete, some data is being pulled from the hook_block_info hooks (specifically the info key) so first we would need to fetch the data from the DB, then invoke the block_info hooks to find the missing data, then alter it to keep the result consistent. At this point it feels like we are doing too much for a quick return, practically duplicating the effort. Also we have no guarantee that every block coming from the DB will have its data properly backfilled from the hook_block_infos, because someone might have just disabled the module providing it and the rehash hasnt yet got to get rid of it.

nagba’s picture

Issue summary: View changes

typo

pwolanin’s picture

Issue summary: View changes

As written this is a potentially infinite loop? The core lock system doesn't have any notion of priority for waiting processes.

In several places core assumes that if another process is running this, we should just wait and then skip the locked code.

sadly core has the same or worse in https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/vari...

psynaptic’s picture

I think we can still do the loop and avoid the infinite loop if we set a limit to the number of iterations. Something like:

$max_attempts = 12;
$attempts = 0;
while (!lock_acquire('_block_rehash_' . $theme) && $attempts < $max_attempts) {
  $attempts++;
  lock_wait('_block_rehash_' . $theme, 5);
}

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.