From 108a4378416a53e709c5eac7f070fc055aa2ff45 Mon Sep 17 00:00:00 2001 From: nerix Date: Sun, 9 Mar 2025 22:44:02 +0100 Subject: [PATCH] fix(eventsub): close connection after timeout (#6059) --- CHANGELOG.md | 2 +- lib/twitch-eventsub-ws/benchmarks/src/parse.cpp | 4 ++-- lib/twitch-eventsub-ws/src/session.cpp | 1 + lib/twitch-eventsub-ws/tests/src/parse.cpp | 4 ++-- tests/src/EventSubMessages.cpp | 5 +++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a4f904c..66bb3dec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,7 +45,7 @@ - Bugfix: Fixed a thick border on Windows 11. (#5836) - Bugfix: Fixed some windows not immediately closing. (#6054) - Dev: Subscriptions to PubSub channel points redemption topics now use no auth token, making it continue to work during PubSub shutdown. (#5947) -- Dev: Add initial experimental EventSub support. (#5837, #5895, #5897, #5904, #5910, #5903, #5915, #5916, #5930, #5935, #5932, #5943, #5952, #5953, #5968, #5973, #5974, #5980, #5981, #5985, #5990, #5992, #5993, #5996, #5995, #6000, #6001, #6002, #6003, #6005, #6007, #6010, #6008, #6012, #6013, #6015, #6017, #6027, #6028, #6035, #6036, #6040, #6041, #6048, #6058) +- Dev: Add initial experimental EventSub support. (#5837, #5895, #5897, #5904, #5910, #5903, #5915, #5916, #5930, #5935, #5932, #5943, #5952, #5953, #5968, #5973, #5974, #5980, #5981, #5985, #5990, #5992, #5993, #5996, #5995, #6000, #6001, #6002, #6003, #6005, #6007, #6010, #6008, #6012, #6013, #6015, #6017, #6027, #6028, #6035, #6036, #6040, #6041, #6048, #6058, #6059) - Dev: Remove unneeded platform specifier for toasts. (#5914) - Dev: Cleanly shutdown on `SIGINT`/`SIGTERM` on Linux & macOS. (#6053) - Dev: Highlight checks now use non-capturing groups for the boundaries. (#5784) diff --git a/lib/twitch-eventsub-ws/benchmarks/src/parse.cpp b/lib/twitch-eventsub-ws/benchmarks/src/parse.cpp index 730fa179..1af797e1 100644 --- a/lib/twitch-eventsub-ws/benchmarks/src/parse.cpp +++ b/lib/twitch-eventsub-ws/benchmarks/src/parse.cpp @@ -174,13 +174,13 @@ void BM_ParseAndHandleMessages(benchmark::State &state) boost::asio::io_context ioc; boost::asio::ssl::context ssl( boost::asio::ssl::context::method::tls_client); - Session sess(ioc, ssl, std::move(listener)); + auto sess = std::make_shared(ioc, ssl, std::move(listener)); for (auto _ : state) { for (const auto &msg : messages) { - boost::system::error_code ec = sess.handleMessage(msg); + boost::system::error_code ec = sess->handleMessage(msg); assert(!ec); } } diff --git a/lib/twitch-eventsub-ws/src/session.cpp b/lib/twitch-eventsub-ws/src/session.cpp index 13d5a3ee..9c21e60e 100644 --- a/lib/twitch-eventsub-ws/src/session.cpp +++ b/lib/twitch-eventsub-ws/src/session.cpp @@ -556,6 +556,7 @@ void Session::checkKeepalive() { this->listener->onClose(std::move(this->listener), {}); } + this->close(); return; } this->receivedMessage = false; diff --git a/lib/twitch-eventsub-ws/tests/src/parse.cpp b/lib/twitch-eventsub-ws/tests/src/parse.cpp index ce7096e3..edff65f7 100644 --- a/lib/twitch-eventsub-ws/tests/src/parse.cpp +++ b/lib/twitch-eventsub-ws/tests/src/parse.cpp @@ -157,8 +157,8 @@ TEST_P(TestHandleMessageP, Run) boost::asio::io_context ioc; boost::asio::ssl::context ssl( boost::asio::ssl::context::method::tls_client); - Session sess(ioc, ssl, std::move(listener)); - auto ec = sess.handleMessage(buf); + auto sess = std::make_shared(ioc, ssl, std::move(listener)); + auto ec = sess->handleMessage(buf); ASSERT_FALSE(ec.failed()) << ec.what() << ec.message() << ec.location().to_string(); } diff --git a/tests/src/EventSubMessages.cpp b/tests/src/EventSubMessages.cpp index ee2b0ad7..3bceeb7c 100644 --- a/tests/src/EventSubMessages.cpp +++ b/tests/src/EventSubMessages.cpp @@ -309,7 +309,8 @@ TEST_P(TestEventSubMessagesP, Run) boost::asio::io_context ioc; boost::asio::ssl::context ssl( boost::asio::ssl::context::method::tls_client); - eventsub::lib::Session sess(ioc, ssl, std::move(listener)); + auto sess = + std::make_shared(ioc, ssl, std::move(listener)); for (const auto inputRef : input) { @@ -328,7 +329,7 @@ TEST_P(TestEventSubMessagesP, Run) auto json = makePayload(eventSubscription->second, inputObj); - auto ec = sess.handleMessage(json); + auto ec = sess->handleMessage(json); ASSERT_FALSE(ec.failed()) << ec.what() << ec.message() << ec.location().to_string(); }