From a570c0e5037b75bb41f731879b4301b900fb6d64 Mon Sep 17 00:00:00 2001 From: vzagorovskiy Date: Fri, 28 Aug 2026 11:47:02 +0300 Subject: [PATCH] Keep the failed nginx config as a .conf.err file When `nginx -t` fails, configure() is meant to move the broken config to .conf.err so the failure can be inspected. renameConfigAsError() unlinked the source file before renaming it, so the rename always failed and the config was simply deleted. The deleteConfig() call after it then removed any .err file left over from an earlier failure. - unlink the destination .err file instead of the source - return the rename promise so the delete does not race it - pass delete_err_file = false so the new .err file survives - drop the stale 4th argument in the success path, which silently made delete_err_file false and left old .err files behind --- backend/internal/nginx.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/internal/nginx.js b/backend/internal/nginx.js index 80cb0c29..128c0046 100644 --- a/backend/internal/nginx.js +++ b/backend/internal/nginx.js @@ -34,7 +34,7 @@ const internalNginx = { // We're deleting this config regardless. // Don't throw errors, as the file may not exist at all // Delete the .err file too - return internalNginx.deleteConfig(host_type, host, false, true); + return internalNginx.deleteConfig(host_type, host, true); }) .then(() => { return internalNginx.generateConfig(host_type, host); @@ -83,10 +83,12 @@ const internalNginx = { meta: combined_meta, }) .then(() => { - internalNginx.renameConfigAsError(host_type, host); + // Keep the failed config as a .err file for inspection + return internalNginx.renameConfigAsError(host_type, host); }) .then(() => { - return internalNginx.deleteConfig(host_type, host, true); + // The rename removed the live config already, don't touch the .err file + return internalNginx.deleteConfig(host_type, host, false); }); }); }) @@ -378,8 +380,8 @@ const internalNginx = { const config_file_err = `${config_file}.err`; return new Promise((resolve /*, reject*/) => { - fs.unlink(config_file, () => { - // ignore result, continue + fs.unlink(config_file_err, () => { + // ignore result, a previous .err file may not exist fs.rename(config_file, config_file_err, () => { // also ignore result, as this is a debugging informative file anyway resolve();