diff options
| author | Stefan Boberg <[email protected]> | 2026-03-17 18:09:48 +0100 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2026-03-17 18:11:03 +0100 |
| commit | a754ae7468ac21b40d4971cca6c6dfa9183e9570 (patch) | |
| tree | ced3a0c4bd4c5660919ba73d43cc349b990d1686 /src/zenserver/zenserver.cpp | |
| parent | changelog (diff) | |
| download | zen-a754ae7468ac21b40d4971cca6c6dfa9183e9570.tar.xz zen-a754ae7468ac21b40d4971cca6c6dfa9183e9570.zip | |
Fix silent exit when second zenserver instance detects port conflict
ZEN_WARN/INFO/CRITICAL calls before InitializeLogging() are silently
discarded. Switch all log calls in ZenServerMain::Run() that precede
InitializeLogging() — the ZenServerState early-exit block, the lock
file retry block, and the catch handlers — to their ZEN_CONSOLE_*
equivalents. Also fix the same issue in ZenServerState::Sweep() and
Snapshot() which had been inconsistently converted to fprintf+std::format.
Diffstat (limited to 'src/zenserver/zenserver.cpp')
| -rw-r--r-- | src/zenserver/zenserver.cpp | 72 |
1 files changed, 39 insertions, 33 deletions
diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp index 49ae1b6ff..38cd5fc75 100644 --- a/src/zenserver/zenserver.cpp +++ b/src/zenserver/zenserver.cpp @@ -619,6 +619,10 @@ ZenServerMain::Run() uint32_t AttachSponsorProcessRetriesLeft = 3; ZenServerState::ZenServerEntry* Entry = ServerState.Lookup(m_ServerOptions.BasePort); + // NOTE: ZEN_CONSOLE_WARN/INFO is used in this block and the lock file block below + // (instead of ZEN_WARN/INFO) because InitializeLogging() has not been called yet at + // this point. ZEN_WARN/INFO would silently discard messages before the logging system + // is initialized. while (Entry) { if (m_ServerOptions.OwnerPid) @@ -628,27 +632,29 @@ ZenServerMain::Run() { if (Ec) { - ZEN_WARN(ZEN_APP_NAME - " exiting, sponsor owner pid {} can not be checked for running state, reason: '{}'. Will not add sponsor " - "to process " - "listening to port {} (pid: {})", - m_ServerOptions.OwnerPid, - Ec.message(), - m_ServerOptions.BasePort, - Entry->Pid.load()); + ZEN_CONSOLE_WARN( + ZEN_APP_NAME + " exiting, sponsor owner pid {} can not be checked for running state, reason: '{}'. Will not add sponsor " + "to process " + "listening to port {} (pid: {})", + m_ServerOptions.OwnerPid, + Ec.message(), + m_ServerOptions.BasePort, + Entry->Pid.load()); } else { - ZEN_WARN(ZEN_APP_NAME - " exiting, sponsor owner pid {} is no longer running, will not add sponsor to process listening to port " - "{} (pid: {})", - m_ServerOptions.OwnerPid, - m_ServerOptions.BasePort, - Entry->Pid.load()); + ZEN_CONSOLE_WARN( + ZEN_APP_NAME + " exiting, sponsor owner pid {} is no longer running, will not add sponsor to process listening to port " + "{} (pid: {})", + m_ServerOptions.OwnerPid, + m_ServerOptions.BasePort, + Entry->Pid.load()); } std::exit(1); } - ZEN_INFO( + ZEN_CONSOLE_INFO( "Looks like there is already a process listening to this port {} (pid: {}), attaching owner pid {} to running instance", m_ServerOptions.BasePort, Entry->Pid.load(), @@ -666,18 +672,18 @@ ZenServerMain::Run() } else { - ZEN_WARN(ZEN_APP_NAME " exiting, failed to add sponsor owner pid {} to process listening to port {} (pid: {})", - m_ServerOptions.OwnerPid, - m_ServerOptions.BasePort, - Entry->Pid.load()); + ZEN_CONSOLE_WARN(ZEN_APP_NAME " exiting, failed to add sponsor owner pid {} to process listening to port {} (pid: {})", + m_ServerOptions.OwnerPid, + m_ServerOptions.BasePort, + Entry->Pid.load()); std::exit(1); } } else { - ZEN_WARN(ZEN_APP_NAME " exiting, there is already a process listening to port {} (pid: {})", - m_ServerOptions.BasePort, - Entry->Pid.load()); + ZEN_CONSOLE_WARN(ZEN_APP_NAME " exiting, there is already a process listening to port {} (pid: {})", + m_ServerOptions.BasePort, + Entry->Pid.load()); std::exit(1); } } @@ -690,19 +696,19 @@ ZenServerMain::Run() if (Ec) { - ZEN_INFO(ZEN_APP_NAME " unable to grab lock at '{}' (reason: '{}'), retrying", LockFilePath, Ec.message()); + ZEN_CONSOLE_INFO(ZEN_APP_NAME " unable to grab lock at '{}' (reason: '{}'), retrying", LockFilePath, Ec.message()); Sleep(100); m_LockFile.Create(LockFilePath, MakeLockData(false), Ec); if (Ec) { - ZEN_INFO(ZEN_APP_NAME " unable to grab lock at '{}' (reason: '{}'), retrying", LockFilePath, Ec.message()); + ZEN_CONSOLE_INFO(ZEN_APP_NAME " unable to grab lock at '{}' (reason: '{}'), retrying", LockFilePath, Ec.message()); Sleep(500); m_LockFile.Create(LockFilePath, MakeLockData(false), Ec); if (Ec) { - ZEN_WARN(ZEN_APP_NAME " exiting, unable to grab lock at '{}' (reason: '{}')", LockFilePath, Ec.message()); + ZEN_CONSOLE_WARN(ZEN_APP_NAME " exiting, unable to grab lock at '{}' (reason: '{}')", LockFilePath, Ec.message()); std::exit(99); } } @@ -736,22 +742,22 @@ ZenServerMain::Run() } catch (const AssertException& AssertEx) { - ZEN_CRITICAL(ZEN_APP_NAME " caught assert exception in main for process {}: {}", - zen::GetCurrentProcessId(), - AssertEx.FullDescription()); + ZEN_CONSOLE_CRITICAL(ZEN_APP_NAME " caught assert exception in main for process {}: {}", + zen::GetCurrentProcessId(), + AssertEx.FullDescription()); RequestApplicationExit(1); } catch (const std::system_error& e) { - ZEN_CRITICAL(ZEN_APP_NAME " caught system error exception in main for process {}: {} ({})", - zen::GetCurrentProcessId(), - e.what(), - e.code().value()); + ZEN_CONSOLE_CRITICAL(ZEN_APP_NAME " caught system error exception in main for process {}: {} ({})", + zen::GetCurrentProcessId(), + e.what(), + e.code().value()); RequestApplicationExit(1); } catch (const std::exception& e) { - ZEN_CRITICAL(ZEN_APP_NAME " caught exception in main for process {}: {}", zen::GetCurrentProcessId(), e.what()); + ZEN_CONSOLE_CRITICAL(ZEN_APP_NAME " caught exception in main for process {}: {}", zen::GetCurrentProcessId(), e.what()); RequestApplicationExit(1); } |