From 040731095e826598124fdb55fc0060ba9e26af21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 19 Aug 2023 23:46:08 +0200 Subject: [PATCH] Fix assertion failure when SQLite connection fails When connecting to the SQLite database fails, e.g. because the `.sqlite` file is corrupted, the server would crash with the assertion "Tried connecting while the connection is in use" when a player joins and performs any action. This is fixed by resetting the use-flag when connecting to the SQLite database fails, which is the same behavior as for the MySQL database connection. --- src/engine/server/databases/sqlite.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/engine/server/databases/sqlite.cpp b/src/engine/server/databases/sqlite.cpp index c72ac73bf49..720b0b25c05 100644 --- a/src/engine/server/databases/sqlite.cpp +++ b/src/engine/server/databases/sqlite.cpp @@ -65,6 +65,8 @@ class CSqliteConnection : public IDbConnection bool m_Done; // no more rows available for Step // returns false, if the query succeeded bool Execute(const char *pQuery, char *pError, int ErrorSize); + // returns true on failure + bool ConnectImpl(char *pError, int ErrorSize); // returns true if an error was formatted bool FormatError(int Result, char *pError, int ErrorSize); @@ -110,9 +112,18 @@ bool CSqliteConnection::Connect(char *pError, int ErrorSize) { if(m_InUse.exchange(true)) { - dbg_assert(0, "Tried connecting while the connection is in use"); + dbg_assert(false, "Tried connecting while the connection is in use"); } + if(ConnectImpl(pError, ErrorSize)) + { + m_InUse.store(false); + return true; + } + return false; +} +bool CSqliteConnection::ConnectImpl(char *pError, int ErrorSize) +{ if(m_pDb != nullptr) { return false;