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.
This commit is contained in:
Alexander A. Klimov 2024-01-26 11:24:33 +01:00
parent 4a05070555
commit e814697af5

View File

@ -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);