From f839707c4a9dc060ca2bd38429c4d7901a5d5d3c Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 25 Nov 2024 17:58:58 +0100 Subject: [PATCH] Timeout#Timeout(): don't pass yield_context to callback It's not used. Also, the callback shall run completely at once. This ensures that it won't (continue to) run once another coroutine on the strand calls Timeout#Cancel(). --- lib/base/io-engine.hpp | 2 +- lib/base/tlsstream.cpp | 2 +- lib/icingadb/redisconnection.hpp | 2 +- lib/methods/ifwapichecktask.cpp | 2 +- lib/remote/apilistener.cpp | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/base/io-engine.hpp b/lib/base/io-engine.hpp index 326f04fdc..83ac9aaab 100644 --- a/lib/base/io-engine.hpp +++ b/lib/base/io-engine.hpp @@ -199,7 +199,7 @@ public: } auto f (onTimeout); - f(std::move(yc)); + f(); }); } diff --git a/lib/base/tlsstream.cpp b/lib/base/tlsstream.cpp index ed8005837..c7f2884f4 100644 --- a/lib/base/tlsstream.cpp +++ b/lib/base/tlsstream.cpp @@ -141,7 +141,7 @@ void AsioTlsStream::GracefulDisconnect(boost::asio::io_context::strand& strand, { Timeout::Ptr shutdownTimeout(new Timeout(strand.context(), strand, boost::posix_time::seconds(10), - [this](boost::asio::yield_context yc) { + [this] { // Forcefully terminate the connection if async_shutdown() blocked more than 10 seconds. ForceDisconnect(); } diff --git a/lib/icingadb/redisconnection.hpp b/lib/icingadb/redisconnection.hpp index f346ba285..9fb0dc52e 100644 --- a/lib/icingadb/redisconnection.hpp +++ b/lib/icingadb/redisconnection.hpp @@ -517,7 +517,7 @@ Timeout::Ptr RedisConnection::MakeTimeout(StreamPtr& stream) m_Strand.context(), m_Strand, boost::posix_time::microseconds(intmax_t(m_ConnectTimeout * 1000000)), - [keepAlive, stream](boost::asio::yield_context yc) { + [keepAlive, stream] { boost::system::error_code ec; stream->lowest_layer().cancel(ec); } diff --git a/lib/methods/ifwapichecktask.cpp b/lib/methods/ifwapichecktask.cpp index 9a62444b6..d5148623a 100644 --- a/lib/methods/ifwapichecktask.cpp +++ b/lib/methods/ifwapichecktask.cpp @@ -457,7 +457,7 @@ void IfwApiCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes *strand, [strand, checkable, cr, psCommand, psHost, expectedSan, psPort, conn, req, checkTimeout, reportResult = std::move(reportResult)](asio::yield_context yc) { Timeout::Ptr timeout = new Timeout(strand->context(), *strand, boost::posix_time::microseconds(int64_t(checkTimeout * 1e6)), - [&conn, &checkable](boost::asio::yield_context yc) { + [&conn, &checkable] { Log(LogNotice, "IfwApiCheckTask") << "Timeout while checking " << checkable->GetReflectionType()->GetName() << " '" << checkable->GetName() << "', cancelling attempt"; diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 9c2a489da..601367e49 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -535,7 +535,7 @@ void ApiListener::ListenerCoroutineProc(boost::asio::yield_context yc, const Sha IoEngine::SpawnCoroutine(*strand, [this, strand, sslConn, remoteEndpoint](asio::yield_context yc) { Timeout::Ptr timeout(new Timeout(strand->context(), *strand, boost::posix_time::microseconds(int64_t(GetConnectTimeout() * 1e6)), - [sslConn, remoteEndpoint](asio::yield_context yc) { + [sslConn, remoteEndpoint] { Log(LogWarning, "ApiListener") << "Timeout while processing incoming connection from " << remoteEndpoint; @@ -586,7 +586,7 @@ void ApiListener::AddConnection(const Endpoint::Ptr& endpoint) lock.unlock(); Timeout::Ptr timeout(new Timeout(strand->context(), *strand, boost::posix_time::microseconds(int64_t(GetConnectTimeout() * 1e6)), - [sslConn, endpoint, host, port](asio::yield_context yc) { + [sslConn, endpoint, host, port] { Log(LogCritical, "ApiListener") << "Timeout while reconnecting to endpoint '" << endpoint->GetName() << "' via host '" << host << "' and port '" << port << "', cancelling attempt"; @@ -687,7 +687,7 @@ void ApiListener::NewClientHandlerInternal( strand->context(), *strand, boost::posix_time::microseconds(intmax_t(Configuration::TlsHandshakeTimeout * 1000000)), - [strand, client](asio::yield_context yc) { + [strand, client] { boost::system::error_code ec; client->lowest_layer().cancel(ec); }