Stop ServerThread immediately on errors

This commit is contained in:
sfan5 2025-01-08 19:31:23 +01:00
parent 9dd09d1056
commit d0d7c11fe1
2 changed files with 14 additions and 2 deletions

View file

@ -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)
{

View file

@ -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());