diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 353714e..d691552 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -3496,27 +3496,7 @@ function drupal_check_memory_limit($required, $memory_limit = NULL) {
  * @return Drupal\Core\Lock\LockBackendInterface
  */
 function lock() {
-  $lock_backend = &drupal_static(__FUNCTION__);
-
-  if (!isset($lock_backend)) {
-    $class_name = variable_get('lock_backend', 'Drupal\Core\Lock\DatabaseLockBackend');
-
-    // Do not allow a WSOD here, if the class does not exists use the default
-    // one.
-    // @todo We should log failed class loading for debugging, but for that we
-    //   need an early watchdog function that logs into a file if the database
-    //   is not present.
-    if (class_exists($class_name)) {
-      $lock_backend = new $class_name();
-    }
-    else {
-      $lock_backend = new DatabaseLockBackend();
-    }
-
-    drupal_register_shutdown_function(array($lock_backend, 'releaseAll'));
-  }
-
-  return $lock_backend;
+  return drupal_container()->get('lock');
 }
 
 /**
diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index 5223cc5..bda0597 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -330,6 +330,14 @@ function install_begin_request(&$install_state) {
     $container->register('config.factory', 'Drupal\Core\Config\ConfigFactory')
       ->addArgument(new Reference('config.storage'))
       ->addArgument(new Reference('event_dispatcher'));
+    // The install process cannot use the database lock backend since the database
+    // is not fully up, so we use a null backend implementation during the
+    // installation process. This will also speed up the installation process.
+    // The site being installed will use the real lock backend when doing AJAX
+    // requests but, except for a WSOD, there is no chance for a a lock to stall
+    // (as opposed to the cache backend) so we can afford having a null
+    // implementation here.
+    $container->register('lock', 'Drupal\Core\Lock\NullLockBackend');
     drupal_container($container);
   }
 
@@ -354,15 +362,6 @@ function install_begin_request(&$install_state) {
   require_once DRUPAL_ROOT . '/core/includes/cache.inc';
   $conf['cache_classes'] = array('cache' => 'Drupal\Core\Cache\InstallBackend');
 
-  // The install process cannot use the database lock backend since the database
-  // is not fully up, so we use a null backend implementation during the
-  // installation process. This will also speed up the installation process.
-  // The site being installed will use the real lock backend when doing AJAX
-  // requests but, except for a WSOD, there is no chance for a a lock to stall
-  // (as opposed to the cache backend) so we can afford having a null
-  // implementation here.
-  $conf['lock_backend'] = 'Drupal\Core\Lock\NullLockBackend';
-
   // Prepare for themed output. We need to run this at the beginning of the
   // page request to avoid a different theme accidentally getting set. (We also
   // need to run it even in the case of command-line installations, to prevent
diff --git a/core/lib/Drupal/Core/Lock/DatabaseLockBackend.php b/core/lib/Drupal/Core/Lock/DatabaseLockBackend.php
index b0ee0a3..44251e3 100644
--- a/core/lib/Drupal/Core/Lock/DatabaseLockBackend.php
+++ b/core/lib/Drupal/Core/Lock/DatabaseLockBackend.php
@@ -15,6 +15,15 @@
 class DatabaseLockBackend extends LockBackendAbstract {
 
   /**
+   * Constructs a new DatabaseLockBackend.
+   */
+  public function __construct() {
+    // __destruct() is causing problems with garbage collections, register a
+    // shutdown function instead.
+    drupal_register_shutdown_function(array($this, 'releaseAll'));
+  }
+
+  /**
    * Implements Drupal\Core\Lock\LockBackedInterface::acquire().
    */
   public function acquire($name, $timeout = 30.0) {
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php
index 96e9017..b09df75 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php
@@ -132,7 +132,7 @@ public function containerBuild($container) {
     global $conf;
     // Keep the container object around for tests.
     $this->container = $container;
-    $conf['lock_backend'] = 'Drupal\Core\Lock\NullLockBackend';
+    $container->register('lock', 'Drupal\Core\Lock\NullLockBackend');
     $conf['cache_classes'] = array('cache' => 'Drupal\Core\Cache\MemoryBackend');
     $container
       ->register('config.storage', 'Drupal\Core\Config\FileStorage')
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
index 4d72998..e8068fa 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
@@ -866,6 +866,11 @@ protected function prepareEnvironment() {
     // Create and set new configuration directories.
     $this->prepareConfigDirectories();
 
+    // Reset statics before the old container is replaced so that objects with a
+    // __destruct() method still have access to it.
+    // @todo: Remove once they have been converted to services.
+    drupal_static_reset();
+
     // Reset and create a new service container.
     $this->container = new ContainerBuilder();
     drupal_container($this->container);
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index 713839e..b95eeaf 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -808,9 +808,8 @@ protected function setUp() {
     $batch = &batch_get();
     $batch = $this->originalBatch;
 
-    // Revert install_begin_request() cache and lock service overrides.
+    // Revert install_begin_request() cache service overrides.
     unset($conf['cache_classes']);
-    unset($conf['lock_backend']);
 
     // Set path variables.
 
diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php
index dd6703b..aaa3464 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php
@@ -181,7 +181,7 @@ protected function variable_set($name, $value) {
    */
   protected function refreshVariables() {
     // No operation if the child has not been upgraded yet.
-    if (!$this->upgradedSite) {
+    if ($this->upgradedSite) {
       global $conf;
       cache('bootstrap')->delete('variables');
       $conf = variable_initialize();
@@ -263,6 +263,9 @@ protected function performUpgrade($register_errors = TRUE) {
     // of the child site directly from this request.
     $this->upgradedSite = TRUE;
 
+    // Force a variable refresh as we only just enabled it.
+    $this->refreshVariables();
+
     // Reload module list for modules that are enabled in the test database
     // but not on the test client.
     system_list_reset();
