Categories
WordPress

Fixing the ‘Another update is currently in progress.’ Error in WordPress

If you ever see the error Another update is currently in progress, it means that WordPress has been updating one of its components (maybe a theme, a plugin or even the WordPress core) and something got messed up and the update process didn’t finish successfully.

You’ll even get that error if you’re updating via WP-CLI:

▶ wp core update 
Updating to version 5.4.1 (en_US)...
Error: Another update is currently in progress.

If you’re not in a hurry, leave the website for 15 minutes (refreshing your page 100 times will not help) and the error should be gone automatically. Reading the rest of this post may also be a good candidate for spending those 15 minutes.

What actually happened?

Whenever an update is launched, WordPress will create a lock, which is saved in the options table. When the update is finished, WordPress deletes that lock entry from the table. If the update got interrupted, the lock won’t be deleted from the database and you’ll end up with that Another update is currently in progress error.

The code from wp-admin/includes/class-core-upgrader.php which triggers the lock is shown below. You’ll notice that the lock is set for 15 minutes – The reason why refreshing the page multiple times won’t do anything.

// Lock to prevent multiple Core Updates occurring.
$lock = WP_Upgrader::create_lock( 'core_updater', 15 * MINUTE_IN_SECONDS );

If you peek into the method definition of create_lock() in wp-admin/includes/class-wp-upgrader.php, you’ll see that the lock is saved to the options table in the format {lockname}.lock. Using that logic, you can expect to find core_updater.lock in the options table.

$lock_option = $lock_name . '.lock';
// Try to lock.
$lock_result = $wpdb->query( $wpdb->prepare( "INSERT IGNORE INTO `$wpdb->options` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $lock_option, time() ) );

For what it’s worth, when the lock is deleted at the end of the WordPress update script, behind the scene, the core_updater.lock entry is deleted from the database.

WP_Upgrader::release_lock( 'core_updater' );
/*
 * Releases an upgrader lock. 
 *
 * @since 4.5.0
 *
 * @see WP_Upgrader::create_lock()	 *
 * @param string $lock_name The name of this unique lock.
 * @return bool True if the lock was successfully released. False on failure.
 */
public static function release_lock( $lock_name ) {
    return delete_option( $lock_name . '.lock' );
}

The Fix

Now that you know the source of the problem, fixing it is trivial – Delete the core_updater.lock from the options table. Either using WP-CLI, PHPMyAdmin, or a PHP file.

The first method and my recommended way involves using WP-CLI, and takes a few seconds to do:

▶ wp option delete core_updater.lock
Success: Deleted 'core_updater.lock' option.

The second method involves going to your PHPMyAdmin, navigating to the options table and manually deleting the entry. Something you would do if you do not have WP-CLI installed on your server. Or maybe run a MySQL query (your database prefix should be different) to delete the entry:

DELETE FROM wp_options WHERE option_name = 'core_updater.lock';

The final method will be using a PHP file. You can use your theme’s functions.php file if you want. Add some code at the end of your file to delete the entry, and reload a page of your website. Don’t forget to remove the code afterwards. I don’t recommend it doing this way though:

delete_option( "core_updater.lock" ); // At the end of functions.php

By now you should no more be getting that message and you can relaunch your updates.