Connect(): don't try next DNS record if operation is canceled

Instead return immediately to meet the caller's expectations.
This commit is contained in:
Alexander A. Klimov 2023-02-28 10:57:54 +01:00
parent d9767cff3f
commit 79f1e0666a
1 changed files with 10 additions and 4 deletions

View File

@ -6,8 +6,10 @@
#include "base/i2-base.hpp"
#include "base/io-engine.hpp"
#include "base/socket.hpp"
#include <boost/asio/error.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/system/system_error.hpp>
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<const boost::system::system_error*>(&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<const boost::system::system_error*>(&ex));
if (se && se->code() == boost::asio::error::operation_aborted || ++current == result.end()) {
throw;
}