From d0d7c11fe12cdfce6dd234c04dc3724fda3a8c6d Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 8 Jan 2025 19:31:23 +0100 Subject: [PATCH] Stop ServerThread immediately on errors --- src/server.cpp | 13 +++++++++++++ src/server.h | 3 +-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index 092528d7a..25fc46605 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -625,6 +625,11 @@ void Server::AsyncRunStep(float dtime, bool initial_step) ZoneScoped; auto framemarker = FrameMarker("Server::AsyncRunStep()-frame").started(); + if (!m_async_fatal_error.get().empty()) { + infostream << "Refusing server step in error state" << std::endl; + return; + } + { // Send blocks to clients SendBlocks(dtime); @@ -3854,6 +3859,14 @@ std::string Server::getBuiltinLuaPath() return porting::path_share + DIR_DELIM + "builtin"; } +void Server::setAsyncFatalError(const std::string &error) +{ + m_async_fatal_error.set(error); + // make sure server steps stop happening immediately + if (m_thread) + m_thread->stop(); +} + // Not thread-safe. void Server::addShutdownError(const ModError &e) { diff --git a/src/server.h b/src/server.h index 560a3452d..407d43d1b 100644 --- a/src/server.h +++ b/src/server.h @@ -344,8 +344,7 @@ public: void setStepSettings(StepSettings spdata) { m_step_settings.store(spdata); } StepSettings getStepSettings() { return m_step_settings.load(); } - inline void setAsyncFatalError(const std::string &error) - { m_async_fatal_error.set(error); } + void setAsyncFatalError(const std::string &error); inline void setAsyncFatalError(const LuaError &e) { setAsyncFatalError(std::string("Lua: ") + e.what());