Skip to content

Commit

Permalink
Fix assertion failure when SQLite connection fails
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Robyt3 committed Aug 22, 2023
1 parent bb14732 commit 0407310
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/engine/server/databases/sqlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0407310

Please sign in to comment.