From 7aabc507e77b5ce0455d38129af29ace0ab2eee5 Mon Sep 17 00:00:00 2001 From: dongresource Date: Mon, 6 Mar 2023 02:08:00 +0100 Subject: [PATCH] Stop handling the current packet if the server is shutting down Previously, terminating a running server from the terminal would sometimes print a benign warning message if the server was currently handling an incoming packet. This happened because CNServer::step() would continue handling the packet after CNServer::kill() released the activeCrit mutex. Now it first re-checks if active has been set to false in the mean time after acquiring the mutex. --- src/core/CNProtocol.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/CNProtocol.cpp b/src/core/CNProtocol.cpp index f1b98d7..c15fdb7 100644 --- a/src/core/CNProtocol.cpp +++ b/src/core/CNProtocol.cpp @@ -473,6 +473,10 @@ void CNServer::start() { } else { std::lock_guard lock(activeCrit); // protect operations on connections + // halt packet handling if server is shutting down + if (!active) + return; + // player sockets if (connections.find(fds[i].fd) == connections.end()) { std::cout << "[WARN] Event on non-existant socket?" << std::endl;