From 9fdc0e54405ff896c9f2f70bc1e757dfaccbcc33 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Wed, 10 Jul 2024 14:14:35 +0200 Subject: [PATCH] MDEV-34546 Windows - no error log entries after startup in XAMPP The server does not log errors after startup when it is started without the --console parameter and not as a service. This issue arises due to an undocumented behavior of FreeConsole() in Windows when only a single process (mariadbd/mysqld) is attached to it, causing the window to close. In this case stderr is redirected to a file before FreeConsole() is called. Procmon shows FreeConsole closing file handle subsequent writes to stderr fail with ERROR_INVALID_HANDLE because WriteFile() cannot operate on the closed handle. This results in losing all messages after startup, including warnings, errors, notes, and crash reports. Additionally, some users reported stderr being redirected to multi-master.info and failing at startup, but this could not be reproduced here. The workaround involves calling FreeConsole() right before the redirection of stdout/stderr. This fix has been tested with XAMPP and via cmd.exe using "start mysqld". Automated testing using MTR is challenging for this case. The fix is only applicable to version 10.5. In later versions, the FreeConsole() call has been removed. --- sql/mysqld.cc | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 7aa90bf357b..31d40b962db 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -4717,6 +4717,10 @@ static int init_server_components() else { my_bool res; +#ifdef _WIN32 + if (!opt_console) + FreeConsole(); // Remove window +#endif #ifndef EMBEDDED_LIBRARY res= reopen_fstreams(log_error_file, stdout, stderr); #else @@ -5585,13 +5589,6 @@ int mysqld_main(int argc, char **argv) init_ssl(); network_init(); -#ifdef _WIN32 - if (!opt_console) - { - FreeConsole(); // Remove window - } -#endif - #ifdef WITH_WSREP // Recover and exit. if (wsrep_recovery)