From 0aa7657aaf99bdf1e513e15b57ce8d938de098a5 Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 5 Jul 2022 11:41:14 +0200 Subject: [PATCH] fixed tracker connections spinning when hostname lookups stall --- ChangeLog | 1 + src/http_connection.cpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index fadeaa11362..902804e7db0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ + * fixed tracker connections spinning when hostname lookups stall * fixed error in pkg-config file generation in Jamfile * improve backwards compatibility with loading magnet link resume files * fix bind-to-device for tracker announces and UPnP diff --git a/src/http_connection.cpp b/src/http_connection.cpp index e78f9b3ec05..bcfa07c9d82 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -404,7 +404,17 @@ void http_connection::on_timeout(std::weak_ptr p // be forgiving of timeout while we're still resolving the hostname // it may be delayed because we're queued up behind another slow lookup - if (c->m_start_time + (c->m_completion_timeout * (int(c->m_resolving_host) + 1)) <= now) + if (c->m_resolving_host + && (c->m_start_time + (c->m_completion_timeout * 2) > now)) + { + ADD_OUTSTANDING_ASYNC("http_connection::on_timeout"); + error_code ec; + c->m_timer.expires_at(c->m_start_time + c->m_completion_timeout * 2, ec); + c->m_timer.async_wait(std::bind(&http_connection::on_timeout, p, _1)); + return; + } + + if (c->m_start_time + c->m_completion_timeout <= now) { // the connection timed out. If we have more endpoints to try, just // close this connection. The on_connect handler will try the next