Commit 9fdc0e54 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

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.
parent 60125a77
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment