diff --git a/includes/lock.inc b/includes/lock.inc
index 42f1906f2572d4a1aa20c7029ca1588d75b978d9..7dd8db30a16343bf380464d1d877eea518f896a0 100644
--- a/includes/lock.inc
+++ b/includes/lock.inc
@@ -74,7 +74,10 @@ function lock_initialize() {
  * Helper function to get this request's unique id.
  */
 function _lock_id() {
-  $lock_id = &drupal_static(__FUNCTION__);
+  // Do not use drupal_static(). This identifier refers to the current
+  // client request, and must not be changed under any circumstances
+  // else the shutdown handler may fail to release our locks.
+  static $lock_id;
 
   if (!isset($lock_id)) {
     // Assign a unique id.