diff options
Diffstat (limited to 'src/zenserver/zenserver.cpp')
| -rw-r--r-- | src/zenserver/zenserver.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp index 49cbbb9fc..ea86c5654 100644 --- a/src/zenserver/zenserver.cpp +++ b/src/zenserver/zenserver.cpp @@ -684,11 +684,33 @@ ZenServerMain::Run() } else { - 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); + // The entry's process failed to pick up our sponsor request after + // multiple attempts. Before reclaiming the entry, verify that the + // PID does not still belong to a zenserver process. If it does, the + // server is alive but unresponsive – fall back to the original error + // path. If the PID is gone or belongs to a different executable the + // entry is genuinely stale and safe to reclaim. + const int StalePid = Entry->Pid.load(); + std::error_code ExeEc; + std::filesystem::path PidExePath = GetProcessExecutablePath(StalePid, ExeEc); + const bool PidIsZenServer = !ExeEc && (PidExePath.filename() == GetRunningExecutablePath().filename()); + if (PidIsZenServer) + { + ZEN_CONSOLE_WARN(ZEN_APP_NAME + " exiting, failed to add sponsor to process on port {} " + "(pid {}); that pid is still a running zenserver instance", + m_ServerOptions.BasePort, + StalePid); + std::exit(1); + } + ZEN_CONSOLE_WARN( + "Failed to add sponsor to process on port {} (pid {}); " + "pid belongs to '{}' – assuming stale entry and reclaiming", + m_ServerOptions.BasePort, + StalePid, + ExeEc ? "<unknown>" : PidExePath.filename().string()); + Entry->Reset(); + Entry = nullptr; } } else |