From 64697e61d792ccd1de2082f7bf3db949c8c8741b Mon Sep 17 00:00:00 2001 From: Audric Date: Fri, 20 Mar 2026 20:28:26 +0100 Subject: [PATCH] Fix event loop blocking on DNS abort in CppDnsLookupWorker abortLookup() called m_result.get() synchronously, blocking the entire event loop while waiting for a potentially long getaddrinfo() call to finish (~18s when the DNS server is unreachable). This caused the HTTP /status endpoint and all other event loop processing to stall whenever a TrunkLink reconnect cycle aborted a pending DNS lookup. Move the future and thread context to a detached cleanup thread so the event loop returns immediately. --- src/async/cpp/AsyncCppDnsLookupWorker.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/async/cpp/AsyncCppDnsLookupWorker.cpp b/src/async/cpp/AsyncCppDnsLookupWorker.cpp index 3a35944..a311eec 100644 --- a/src/async/cpp/AsyncCppDnsLookupWorker.cpp +++ b/src/async/cpp/AsyncCppDnsLookupWorker.cpp @@ -45,6 +45,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include #include #include +#include /**************************************************************************** @@ -249,11 +250,6 @@ bool CppDnsLookupWorker::doLookup(void) void CppDnsLookupWorker::abortLookup(void) { - if (m_result.valid()) - { - m_result.get(); - } - int fd = m_notifier_watch.fd(); if (fd >= 0) { @@ -261,7 +257,20 @@ void CppDnsLookupWorker::abortLookup(void) close(fd); } - m_ctx.reset(); + if (m_result.valid()) + { + // Move the future and context to a detached thread so the event loop + // is not blocked waiting for a potentially long getaddrinfo() call. + auto result = std::move(m_result); + auto ctx = std::move(m_ctx); + std::thread([result = std::move(result), ctx = std::move(ctx)]() mutable { + result.get(); + }).detach(); + } + else + { + m_ctx.reset(); + } } /* CppDnsLookupWorker::abortLookup */