Skip to content

Commit 5ddc0f6

Browse files
committed
fix(database): MySQL reconnection
1 parent d137528 commit 5ddc0f6

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/database/Database.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ bool Database::Connect()
2424
}
2525

2626
my_bool my_true = true;
27-
mysql_options(this->connection, MYSQL_OPT_RECONNECT, (const char *)&my_true);
27+
mysql_options(this->connection, MYSQL_OPT_RECONNECT, &my_true);
2828

2929
if (mysql_real_connect(this->connection, this->m_hostname.c_str(), this->m_username.c_str(), this->m_password.c_str(), this->m_database.c_str(), this->m_port, nullptr, 0) == nullptr)
3030
{

src/plugins/core/scripting/database.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ void DatabaseQueryThread()
7777
try
7878
{
7979
std::string error = queue.db->GetError();
80+
if (error == "MySQL server has gone away")
81+
if (queue.db->Connect())
82+
{
83+
delete ((luabridge::LuaRef *)queue.callback);
84+
continue;
85+
}
86+
else
87+
error = queue.db->GetError();
88+
8089
if (ref.isFunction())
8190
ref(error.size() == 0 ? luabridge::LuaRef(state) : error, tbl);
8291
}

0 commit comments

Comments
 (0)