From 79f1e0666a10c7b97532f9f1731a62f14f3496af Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 28 Feb 2023 10:57:54 +0100 Subject: [PATCH] Connect(): don't try next DNS record if operation is canceled Instead return immediately to meet the caller's expectations. --- lib/base/tcpsocket.hpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/base/tcpsocket.hpp b/lib/base/tcpsocket.hpp index e0f502256..471ad8d23 100644 --- a/lib/base/tcpsocket.hpp +++ b/lib/base/tcpsocket.hpp @@ -6,8 +6,10 @@ #include "base/i2-base.hpp" #include "base/io-engine.hpp" #include "base/socket.hpp" +#include #include #include +#include namespace icinga { @@ -50,8 +52,10 @@ void Connect(Socket& socket, const String& node, const String& service) socket.connect(current->endpoint()); break; - } catch (const std::exception&) { - if (++current == result.end()) { + } catch (const std::exception& ex) { + auto se (dynamic_cast(&ex)); + + if (se && se->code() == boost::asio::error::operation_aborted || ++current == result.end()) { throw; } @@ -79,8 +83,10 @@ void Connect(Socket& socket, const String& node, const String& service, boost::a socket.async_connect(current->endpoint(), yc); break; - } catch (const std::exception&) { - if (++current == result.end()) { + } catch (const std::exception& ex) { + auto se (dynamic_cast(&ex)); + + if (se && se->code() == boost::asio::error::operation_aborted || ++current == result.end()) { throw; }