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().
This commit is contained in:
Alexander A. Klimov 2024-11-25 17:58:58 +01:00 committed by Yonas Habteab
parent 7b30cb3431
commit f839707c4a
5 changed files with 7 additions and 7 deletions

View File

@ -199,7 +199,7 @@ public:
} }
auto f (onTimeout); auto f (onTimeout);
f(std::move(yc)); f();
}); });
} }

View File

@ -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), 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. // Forcefully terminate the connection if async_shutdown() blocked more than 10 seconds.
ForceDisconnect(); ForceDisconnect();
} }

View File

@ -517,7 +517,7 @@ Timeout::Ptr RedisConnection::MakeTimeout(StreamPtr& stream)
m_Strand.context(), m_Strand.context(),
m_Strand, m_Strand,
boost::posix_time::microseconds(intmax_t(m_ConnectTimeout * 1000000)), boost::posix_time::microseconds(intmax_t(m_ConnectTimeout * 1000000)),
[keepAlive, stream](boost::asio::yield_context yc) { [keepAlive, stream] {
boost::system::error_code ec; boost::system::error_code ec;
stream->lowest_layer().cancel(ec); stream->lowest_layer().cancel(ec);
} }

View File

@ -457,7 +457,7 @@ void IfwApiCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
*strand, *strand,
[strand, checkable, cr, psCommand, psHost, expectedSan, psPort, conn, req, checkTimeout, reportResult = std::move(reportResult)](asio::yield_context yc) { [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)), 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") Log(LogNotice, "IfwApiCheckTask")
<< "Timeout while checking " << checkable->GetReflectionType()->GetName() << "Timeout while checking " << checkable->GetReflectionType()->GetName()
<< " '" << checkable->GetName() << "', cancelling attempt"; << " '" << checkable->GetName() << "', cancelling attempt";

View File

@ -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) { 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)), 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") Log(LogWarning, "ApiListener")
<< "Timeout while processing incoming connection from " << remoteEndpoint; << "Timeout while processing incoming connection from " << remoteEndpoint;
@ -586,7 +586,7 @@ void ApiListener::AddConnection(const Endpoint::Ptr& endpoint)
lock.unlock(); lock.unlock();
Timeout::Ptr timeout(new Timeout(strand->context(), *strand, boost::posix_time::microseconds(int64_t(GetConnectTimeout() * 1e6)), 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") Log(LogCritical, "ApiListener")
<< "Timeout while reconnecting to endpoint '" << endpoint->GetName() << "' via host '" << host << "Timeout while reconnecting to endpoint '" << endpoint->GetName() << "' via host '" << host
<< "' and port '" << port << "', cancelling attempt"; << "' and port '" << port << "', cancelling attempt";
@ -687,7 +687,7 @@ void ApiListener::NewClientHandlerInternal(
strand->context(), strand->context(),
*strand, *strand,
boost::posix_time::microseconds(intmax_t(Configuration::TlsHandshakeTimeout * 1000000)), boost::posix_time::microseconds(intmax_t(Configuration::TlsHandshakeTimeout * 1000000)),
[strand, client](asio::yield_context yc) { [strand, client] {
boost::system::error_code ec; boost::system::error_code ec;
client->lowest_layer().cancel(ec); client->lowest_layer().cancel(ec);
} }