Merge pull request #9815 from Icinga/2.13.8/stuck

Don't hang in timed out connection attempt
This commit is contained in:
Alexander Aleksandrovič Klimov 2023-07-04 17:34:24 +02:00 committed by GitHub
commit 8fbfb2f816
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 45 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;
}

View File

@ -734,6 +734,7 @@ void ApiListener::NewClientHandlerInternal(
ClientType ctype;
try {
if (role == RoleClient) {
JsonRpc::SendMessage(client, new Dictionary({
{ "jsonrpc", "2.0" },
@ -790,6 +791,13 @@ void ApiListener::NewClientHandlerInternal(
ctype = ClientHttp;
}
}
} catch (const boost::system::system_error& systemError) {
if (systemError.code() == boost::asio::error::operation_aborted) {
shutDownIfNeeded.Cancel();
}
throw;
}
if (ctype == ClientJsonRpc) {
Log(LogNotice, "ApiListener", "New JSON-RPC client");