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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 14 deletions

View file

@ -2,6 +2,7 @@
## Unversioned ## Unversioned
- Bugfix: Fixed a data race when disconnecting from Twitch PubSub. (#4771)
- Dev: Fixed UTF16 encoding of `modes` file for the installer. (#4791) - Dev: Fixed UTF16 encoding of `modes` file for the installer. (#4791)
- Dev: Temporarily disable High DPI scaling on Qt6 builds on Windows. (#4767) - Dev: Temporarily disable High DPI scaling on Qt6 builds on Windows. (#4767)
- Dev: Tests now run on Ubuntu 22.04 instead of 20.04 to loosen C++ restrictions in tests. (#4774) - Dev: Tests now run on Ubuntu 22.04 instead of 20.04 to loosen C++ restrictions in tests. (#4774)

View file

@ -45,9 +45,15 @@ void PubSubClient::stop()
void PubSubClient::close(const std::string &reason, void PubSubClient::close(const std::string &reason,
websocketpp::close::status::value code) websocketpp::close::status::value code)
{ {
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; WebsocketErrorCode ec;
auto conn = this->websocketClient_.get_con_from_hdl(this->handle_, ec); auto conn =
this->websocketClient_.get_con_from_hdl(this->handle_, ec);
if (ec) if (ec)
{ {
qCDebug(chatterinoPubSub) qCDebug(chatterinoPubSub)
@ -58,9 +64,11 @@ void PubSubClient::close(const std::string &reason,
conn->close(code, reason, ec); conn->close(code, reason, ec);
if (ec) if (ec)
{ {
qCDebug(chatterinoPubSub) << "Error closing:" << ec.message().c_str(); qCDebug(chatterinoPubSub)
<< "Error closing:" << ec.message().c_str();
return; return;
} }
});
} }
bool PubSubClient::listen(PubSubListenMessage msg) bool PubSubClient::listen(PubSubListenMessage msg)