Commit 1f54cb0efa4 for woocommerce
commit 1f54cb0efa4b11744c1fc4d14baeade4e3fb2a1f
Author: James Kemp <me@jckemp.com>
Date: Mon Nov 16 06:36:20 2026 +0100
Stop duplicate wc_installing database errors during upgrade lock contention (#70985)
diff --git a/plugins/woocommerce/changelog/70985-fix-70899-installation-lock-contention-logs-2 b/plugins/woocommerce/changelog/70985-fix-70899-installation-lock-contention-logs-2
new file mode 100644
index 00000000000..5f079f6dab6
--- /dev/null
+++ b/plugins/woocommerce/changelog/70985-fix-70899-installation-lock-contention-logs-2
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Stop logging spurious database errors when several requests try to run a WooCommerce update at the same time.
diff --git a/plugins/woocommerce/includes/class-wc-install.php b/plugins/woocommerce/includes/class-wc-install.php
index 981c25b19d7..6e31a9f62b4 100644
--- a/plugins/woocommerce/includes/class-wc-install.php
+++ b/plugins/woocommerce/includes/class-wc-install.php
@@ -751,10 +751,10 @@ class WC_Install {
private static function create_lock(): bool {
global $wpdb;
- // Insert will fail if it already exists so this functions as a mutex.
+ // INSERT IGNORE affects no rows if another request holds the lock, so contention isn't logged as a DB error.
$created_lock = $wpdb->query(
$wpdb->prepare(
- "INSERT INTO {$wpdb->options} (option_name, option_value, autoload) VALUES ('wc_installing', %d, 'no')",
+ "INSERT IGNORE INTO {$wpdb->options} (option_name, option_value, autoload) VALUES ('wc_installing', %d, 'no')",
time()
)
);
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-install-test.php b/plugins/woocommerce/tests/php/includes/class-wc-install-test.php
index 8b245767fad..ae302238a5e 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-install-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-install-test.php
@@ -929,6 +929,32 @@ class WC_Install_Test extends \WC_Unit_Test_Case {
);
}
+ /**
+ * @testdox Should not log a database error or take over a fresh installation lock held by another request.
+ */
+ public function test_install_lock_contention_does_not_log_database_error(): void {
+ global $wpdb, $EZSQL_ERROR;
+
+ $lock_value = (string) time();
+ $wpdb->query(
+ $wpdb->prepare(
+ "INSERT INTO {$wpdb->options} (option_name, option_value, autoload) VALUES ('wc_installing', %s, 'no')",
+ $lock_value
+ )
+ );
+
+ $errors_before = count( (array) $EZSQL_ERROR );
+
+ WC_Install::install();
+
+ $this->assertCount( $errors_before, (array) $EZSQL_ERROR, 'Lock contention must not record a database error.' );
+ $this->assertSame(
+ $lock_value,
+ $wpdb->get_var( "SELECT option_value FROM {$wpdb->options} WHERE option_name = 'wc_installing'" ),
+ 'A fresh lock held elsewhere must not be taken over or released.'
+ );
+ }
+
/**
* Rebuilds the patterns through the real registration, so the test exercises the content
* BlockTypesController ships rather than a copy of it that could drift. Registering a pattern that