mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-30 09:04:35 +02:00
Merge pull request #9815 from Icinga/2.13.8/stuck
Don't hang in timed out connection attempt
This commit is contained in:
commit
8fbfb2f816
@ -6,8 +6,10 @@
|
|||||||
#include "base/i2-base.hpp"
|
#include "base/i2-base.hpp"
|
||||||
#include "base/io-engine.hpp"
|
#include "base/io-engine.hpp"
|
||||||
#include "base/socket.hpp"
|
#include "base/socket.hpp"
|
||||||
|
#include <boost/asio/error.hpp>
|
||||||
#include <boost/asio/ip/tcp.hpp>
|
#include <boost/asio/ip/tcp.hpp>
|
||||||
#include <boost/asio/spawn.hpp>
|
#include <boost/asio/spawn.hpp>
|
||||||
|
#include <boost/system/system_error.hpp>
|
||||||
|
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
@ -50,8 +52,10 @@ void Connect(Socket& socket, const String& node, const String& service)
|
|||||||
socket.connect(current->endpoint());
|
socket.connect(current->endpoint());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception& ex) {
|
||||||
if (++current == result.end()) {
|
auto se (dynamic_cast<const boost::system::system_error*>(&ex));
|
||||||
|
|
||||||
|
if (se && se->code() == boost::asio::error::operation_aborted || ++current == result.end()) {
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,8 +83,10 @@ void Connect(Socket& socket, const String& node, const String& service, boost::a
|
|||||||
socket.async_connect(current->endpoint(), yc);
|
socket.async_connect(current->endpoint(), yc);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception& ex) {
|
||||||
if (++current == result.end()) {
|
auto se (dynamic_cast<const boost::system::system_error*>(&ex));
|
||||||
|
|
||||||
|
if (se && se->code() == boost::asio::error::operation_aborted || ++current == result.end()) {
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -734,46 +734,8 @@ void ApiListener::NewClientHandlerInternal(
|
|||||||
|
|
||||||
ClientType ctype;
|
ClientType ctype;
|
||||||
|
|
||||||
if (role == RoleClient) {
|
try {
|
||||||
JsonRpc::SendMessage(client, new Dictionary({
|
if (role == RoleClient) {
|
||||||
{ "jsonrpc", "2.0" },
|
|
||||||
{ "method", "icinga::Hello" },
|
|
||||||
{ "params", new Dictionary({
|
|
||||||
{ "version", (double)l_AppVersionInt },
|
|
||||||
{ "capabilities", (double)l_MyCapabilities }
|
|
||||||
}) }
|
|
||||||
}), yc);
|
|
||||||
|
|
||||||
client->async_flush(yc);
|
|
||||||
|
|
||||||
ctype = ClientJsonRpc;
|
|
||||||
} else {
|
|
||||||
{
|
|
||||||
boost::system::error_code ec;
|
|
||||||
|
|
||||||
if (client->async_fill(yc[ec]) == 0u) {
|
|
||||||
if (identity.IsEmpty()) {
|
|
||||||
Log(LogInformation, "ApiListener")
|
|
||||||
<< "No data received on new API connection " << conninfo << ". "
|
|
||||||
<< "Ensure that the remote endpoints are properly configured in a cluster setup.";
|
|
||||||
} else {
|
|
||||||
Log(LogWarning, "ApiListener")
|
|
||||||
<< "No data received on new API connection " << conninfo << " for identity '" << identity << "'. "
|
|
||||||
<< "Ensure that the remote endpoints are properly configured in a cluster setup.";
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char firstByte = 0;
|
|
||||||
|
|
||||||
{
|
|
||||||
asio::mutable_buffer firstByteBuf (&firstByte, 1);
|
|
||||||
client->peek(firstByteBuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (firstByte >= '0' && firstByte <= '9') {
|
|
||||||
JsonRpc::SendMessage(client, new Dictionary({
|
JsonRpc::SendMessage(client, new Dictionary({
|
||||||
{ "jsonrpc", "2.0" },
|
{ "jsonrpc", "2.0" },
|
||||||
{ "method", "icinga::Hello" },
|
{ "method", "icinga::Hello" },
|
||||||
@ -787,8 +749,54 @@ void ApiListener::NewClientHandlerInternal(
|
|||||||
|
|
||||||
ctype = ClientJsonRpc;
|
ctype = ClientJsonRpc;
|
||||||
} else {
|
} else {
|
||||||
ctype = ClientHttp;
|
{
|
||||||
|
boost::system::error_code ec;
|
||||||
|
|
||||||
|
if (client->async_fill(yc[ec]) == 0u) {
|
||||||
|
if (identity.IsEmpty()) {
|
||||||
|
Log(LogInformation, "ApiListener")
|
||||||
|
<< "No data received on new API connection " << conninfo << ". "
|
||||||
|
<< "Ensure that the remote endpoints are properly configured in a cluster setup.";
|
||||||
|
} else {
|
||||||
|
Log(LogWarning, "ApiListener")
|
||||||
|
<< "No data received on new API connection " << conninfo << " for identity '" << identity << "'. "
|
||||||
|
<< "Ensure that the remote endpoints are properly configured in a cluster setup.";
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char firstByte = 0;
|
||||||
|
|
||||||
|
{
|
||||||
|
asio::mutable_buffer firstByteBuf (&firstByte, 1);
|
||||||
|
client->peek(firstByteBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (firstByte >= '0' && firstByte <= '9') {
|
||||||
|
JsonRpc::SendMessage(client, new Dictionary({
|
||||||
|
{ "jsonrpc", "2.0" },
|
||||||
|
{ "method", "icinga::Hello" },
|
||||||
|
{ "params", new Dictionary({
|
||||||
|
{ "version", (double)l_AppVersionInt },
|
||||||
|
{ "capabilities", (double)l_MyCapabilities }
|
||||||
|
}) }
|
||||||
|
}), yc);
|
||||||
|
|
||||||
|
client->async_flush(yc);
|
||||||
|
|
||||||
|
ctype = ClientJsonRpc;
|
||||||
|
} else {
|
||||||
|
ctype = ClientHttp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (const boost::system::system_error& systemError) {
|
||||||
|
if (systemError.code() == boost::asio::error::operation_aborted) {
|
||||||
|
shutDownIfNeeded.Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctype == ClientJsonRpc) {
|
if (ctype == ClientJsonRpc) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user