From e814697af5f254e4c315144c2f086f36122fa5c0 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 26 Jan 2024 11:24:33 +0100 Subject: [PATCH] ApiListener#AddConnection(): start connect timeout after DNS resolution ASIO DNS resolution can't be cancelled. If it takes longer than ApiListener#connect_timeout, the latter becomes a no-op as it cancels socket I/O which doesn't even start before DNS resolution. --- lib/remote/apilistener.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 85443e218..e7cf221ca 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -584,6 +584,8 @@ void ApiListener::AddConnection(const Endpoint::Ptr& endpoint) lock.unlock(); + auto ips (Resolve(host, port, yc)); + Timeout::Ptr timeout(new Timeout(strand->context(), *strand, boost::posix_time::microseconds(int64_t(GetConnectTimeout() * 1e6)), [sslConn, endpoint, host, port](asio::yield_context yc) { Log(LogCritical, "ApiListener") @@ -596,7 +598,7 @@ void ApiListener::AddConnection(const Endpoint::Ptr& endpoint) )); Defer cancelTimeout([&timeout]() { timeout->Cancel(); }); - Connect(sslConn->lowest_layer(), host, port, yc); + Connect(sslConn->lowest_layer(), ips, yc); NewClientHandler(yc, strand, sslConn, endpoint->GetName(), RoleClient);