fix: eventsub stopped flag join (#6136)

This commit is contained in:
pajlada
2025-07-20 12:13:41 +02:00
committed by GitHub
parent 70eefa368f
commit 1ed5a32fd1
3 changed files with 21 additions and 7 deletions
+1
View File
@@ -63,6 +63,7 @@
- Dev: Refactored `Notebook`-related enums into their own file. (#6220)
- Dev: Refactored `SettingWidget::dropdown` for string enums to the source file. (#6293)
- Dev: Don't try to save emote popup bounds if we're quitting. (#6292)
- Dev: Only carefully join EventSub controller thread. (#6136)
- Dev: Remove `ChannelPageView::addCheckbox`. (#6305)
- Dev: Remove `ChannelPageView::addIntInput`. (#6306)
- Dev: Implemented customizable display names for enums. (#6238)
+18 -7
View File
@@ -40,6 +40,8 @@ const auto &LOG = chatterinoTwitchEventSub;
namespace chatterino::eventsub {
using namespace std::literals::chrono_literals;
class QLogProxy : public lib::Logger
{
public:
@@ -79,6 +81,11 @@ Controller::Controller()
std::tie(this->eventSubHost, this->eventSubPort, this->eventSubPath) =
getEventSubHost();
this->thread = std::make_unique<std::thread>([this] {
// make sure we set in any case, even exceptions
auto guard = qScopeGuard([&] {
this->stoppedFlag.set();
});
this->ioContext.run();
});
renameThread(*this->thread, "C2EventSub");
@@ -111,16 +118,20 @@ Controller::~Controller()
this->work.reset();
if (this->thread->joinable())
if (!this->thread->joinable())
{
this->thread->join();
}
else
{
qCWarning(LOG) << "Thread not joinable";
qCInfo(LOG) << "Controller dtor end (not joinable)";
return;
}
qCInfo(LOG) << "Controller dtor end";
if (this->stoppedFlag.waitFor(250ms))
{
this->thread->join();
qCInfo(LOG) << "Controller dtor end (joined)";
return;
}
qCWarning(LOG) << "Controller dtor end (stopped flag didn't stop)";
}
void Controller::removeRef(const SubscriptionRequest &request)
@@ -5,6 +5,7 @@
#include "twitch-eventsub-ws/logger.hpp"
#include "twitch-eventsub-ws/session.hpp"
#include "util/ExponentialBackoff.hpp"
#include "util/OnceFlag.hpp"
#include "util/ThreadGuard.hpp"
#include <boost/asio/executor_work_guard.hpp>
@@ -149,6 +150,7 @@ private:
std::unordered_map<SubscriptionRequest, Subscription> subscriptions;
std::atomic<bool> quitting = false;
OnceFlag stoppedFlag;
};
class DummyController : public IController