From a8d65a55b04713678da7193ab8be5b74490fc5b7 Mon Sep 17 00:00:00 2001 From: "Mr. Nickson" <259025431+mrnickson-hue@users.noreply.github.com> Date: Mon, 5 Oct 2026 17:48:50 +0300 Subject: [PATCH] fix(update): run the database migration before starting the service (#6729) update_x-ui() started x-ui.service and then called config_after_update right away, which runs `x-ui setting -show true` and `x-ui migrate`. The service and the CLI each run InitDB(), and with it every schema migration, on the same database at the same time. On an upgrade that adds schema, the loser exits with an error. Upgrading 3.8.5 to 3.9.0 stopped the service with "duplicate column name: exclude_from_sub", and only Restart=on-failure brought it back 5 s later. Tolerating the duplicate-column error in the column helpers is not enough. The same race also hits the tables new in 3.9.0: concurrent InitDB fails with "table `node_pending_resets` already exists" and "table `tuic_traffic_receipts` already exists". The cause is two processes migrating at once, so the fix is to stop that from happening during update. Run `x-ui migrate` to completion before the service is started, on both the systemd and the OpenRC path. This mirrors install.sh, whose config_after_install already migrates before the first start. The service and the follow-up CLI calls then find the schema current, and their InitDB has nothing to change. Refs #6728 --- update.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/update.sh b/update.sh index 4cd2f2326..894145bf7 100755 --- a/update.sh +++ b/update.sh @@ -1171,6 +1171,11 @@ update_x-ui() { chmod 640 ${xui_folder}/bin/config.json > /dev/null 2>&1 fi + # Finish the schema/data migrations before the service starts, so the service and + # config_after_update's CLI calls never run them on the same database at once (#6728). + echo -e "${green}Migrating database...${plain}" + "${xui_folder}/x-ui" migrate + if [[ $release == "alpine" ]]; then echo -e "${green}Downloading and installing startup unit x-ui.rc...${plain}" xui_rc_temp="/etc/init.d/x-ui.tmp.$$"