Problem/Motivation

_lock_id() currently uses drupal_static() for its unique ID for the request. There is no reason for the additional overhead, because the request does not change during... the request. Furthermore, if something alters clears the cache, the token will be erased and will change at the next _lock_id() call. This means that the shutdown handler won't erase the original lock and it will be stuck.

Proposed resolution

Replace with a simple static variable declaration, and document why this is important in a comment.

Remaining tasks

D8 patch is RTBC in #1216886-4: _lock_id() shouldn't use drupal_static(), any cache clear would potentially make locks stall. Cherry-pick for D7 commit.

Consider overall issue of drupal_static() use in D8.

User interface changes

None.

API changes

None.

Original report by @pounard

Hello,

Actual _lock_id() implementation (default lock.inc implementation) uses drupal_static() for caching statically the unique page request identifier.

This drupal_static() usage is useless because the request doesn't change while running (WTF?!), and is dangerous because if someone messes up with drupal_static() cache, or clear it, the token will be erased and will change at the next _lock_id() call.

If this happens, the shutdown handler won't erase stalled locks set previousle to the drupal_static() cache clear.

Patch attached, should work for both 8.x and 7.x.

Comments

pounard’s picture

Status: Active » Needs review
catch’s picture

Patch looks good. I have had to file loads of these "do not use drupal_static()" issues, we should seriously think about rolling it back or otherwise curtailing it in D8.

Instead of "// drupal_static() usage here is useless. "

Could we use "// Do not use drupal_static()."?

pounard’s picture

Yes, makes no real difference to me, so whatever suits you.

pounard’s picture

catch’s picture

Status: Needs review » Reviewed & tested by the community

Thanks.

catch’s picture

Issue tags: +Needs backport to D7
pounard’s picture

For D7, the same patch file has chances to pass. Better way to do it would be to cherry-pick the commit from 8.x branch to 7.x branch instead of making a new one.

xjm’s picture

Added summary.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x and 8.x. Thanks catch.

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.