mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-16 18:24:31 +02:00
Close client connections if we haven't received any messages in some time
refs #8485
This commit is contained in:
parent
2b44fcb571
commit
a3ccd2a1fb
@ -45,6 +45,11 @@ ApiClient::ApiClient(const String& identity, bool authenticated, const TlsStream
|
|||||||
void ApiClient::Start(void)
|
void ApiClient::Start(void)
|
||||||
{
|
{
|
||||||
m_Stream->RegisterDataHandler(boost::bind(&ApiClient::DataAvailableHandler, this));
|
m_Stream->RegisterDataHandler(boost::bind(&ApiClient::DataAvailableHandler, this));
|
||||||
|
|
||||||
|
m_TimeoutTimer = new Timer();
|
||||||
|
m_TimeoutTimer->OnTimerExpired.connect(boost::bind(&ApiClient::TimeoutTimerHandler, this));
|
||||||
|
m_TimeoutTimer->SetInterval(15);
|
||||||
|
m_TimeoutTimer->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
String ApiClient::GetIdentity(void) const
|
String ApiClient::GetIdentity(void) const
|
||||||
@ -84,8 +89,6 @@ void ApiClient::SendMessageSync(const Dictionary::Ptr& message)
|
|||||||
if (m_Stream->IsEof())
|
if (m_Stream->IsEof())
|
||||||
return;
|
return;
|
||||||
JsonRpc::SendMessage(m_Stream, message);
|
JsonRpc::SendMessage(m_Stream, message);
|
||||||
if (message->Get("method") != "log::SetLogPosition")
|
|
||||||
m_Seen = Utility::GetTime();
|
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
std::ostringstream info;
|
std::ostringstream info;
|
||||||
info << "Error while sending JSON-RPC message for identity '" << m_Identity << "'";
|
info << "Error while sending JSON-RPC message for identity '" << m_Identity << "'";
|
||||||
@ -128,7 +131,6 @@ bool ApiClient::ProcessMessage(void)
|
|||||||
if (srs != StatusNewItem)
|
if (srs != StatusNewItem)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (message->Get("method") != "log::SetLogPosition")
|
|
||||||
m_Seen = Utility::GetTime();
|
m_Seen = Utility::GetTime();
|
||||||
|
|
||||||
if (m_Endpoint && message->Contains("ts")) {
|
if (m_Endpoint && message->Contains("ts")) {
|
||||||
@ -254,3 +256,9 @@ Value RequestCertificateHandler(const MessageOrigin& origin, const Dictionary::P
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ApiClient::TimeoutTimerHandler(void)
|
||||||
|
{
|
||||||
|
if (Utility::GetTime() - 60 > m_Seen)
|
||||||
|
Disconnect();
|
||||||
|
}
|
||||||
|
@ -72,6 +72,7 @@ private:
|
|||||||
ConnectionRole m_Role;
|
ConnectionRole m_Role;
|
||||||
double m_Seen;
|
double m_Seen;
|
||||||
double m_NextHeartbeat;
|
double m_NextHeartbeat;
|
||||||
|
Timer::Ptr m_TimeoutTimer;
|
||||||
|
|
||||||
StreamReadContext m_Context;
|
StreamReadContext m_Context;
|
||||||
|
|
||||||
@ -80,6 +81,8 @@ private:
|
|||||||
bool ProcessMessage(void);
|
bool ProcessMessage(void);
|
||||||
void DataAvailableHandler(void);
|
void DataAvailableHandler(void);
|
||||||
void SendMessageSync(const Dictionary::Ptr& request);
|
void SendMessageSync(const Dictionary::Ptr& request);
|
||||||
|
|
||||||
|
void TimeoutTimerHandler(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user