Fix data race in PubSub (#4771)

This commit is contained in:
pajlada
2023-08-27 23:35:38 +02:00
committed by GitHub
parent 14731012ad
commit 4c942a2a42
2 changed files with 23 additions and 14 deletions
+22 -14
View File
@@ -45,22 +45,30 @@ void PubSubClient::stop()
void PubSubClient::close(const std::string &reason,
websocketpp::close::status::value code)
{
WebsocketErrorCode ec;
boost::asio::post(
this->websocketClient_.get_io_service().get_executor(),
[this, reason, code] {
// We need to post this request to the io service executor
// to ensure the weak pointer used in get_con_from_hdl is used in a safe way
WebsocketErrorCode ec;
auto conn = this->websocketClient_.get_con_from_hdl(this->handle_, ec);
if (ec)
{
qCDebug(chatterinoPubSub)
<< "Error getting con:" << ec.message().c_str();
return;
}
auto conn =
this->websocketClient_.get_con_from_hdl(this->handle_, ec);
if (ec)
{
qCDebug(chatterinoPubSub)
<< "Error getting con:" << ec.message().c_str();
return;
}
conn->close(code, reason, ec);
if (ec)
{
qCDebug(chatterinoPubSub) << "Error closing:" << ec.message().c_str();
return;
}
conn->close(code, reason, ec);
if (ec)
{
qCDebug(chatterinoPubSub)
<< "Error closing:" << ec.message().c_str();
return;
}
});
}
bool PubSubClient::listen(PubSubListenMessage msg)