mirror of https://github.com/Icinga/icinga2.git
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)
|
||||
{
|
||||
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
|
||||
|
@ -84,8 +89,6 @@ void ApiClient::SendMessageSync(const Dictionary::Ptr& message)
|
|||
if (m_Stream->IsEof())
|
||||
return;
|
||||
JsonRpc::SendMessage(m_Stream, message);
|
||||
if (message->Get("method") != "log::SetLogPosition")
|
||||
m_Seen = Utility::GetTime();
|
||||
} catch (const std::exception& ex) {
|
||||
std::ostringstream info;
|
||||
info << "Error while sending JSON-RPC message for identity '" << m_Identity << "'";
|
||||
|
@ -128,7 +131,6 @@ bool ApiClient::ProcessMessage(void)
|
|||
if (srs != StatusNewItem)
|
||||
return false;
|
||||
|
||||
if (message->Get("method") != "log::SetLogPosition")
|
||||
m_Seen = Utility::GetTime();
|
||||
|
||||
if (m_Endpoint && message->Contains("ts")) {
|
||||
|
@ -254,3 +256,9 @@ Value RequestCertificateHandler(const MessageOrigin& origin, const Dictionary::P
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
void ApiClient::TimeoutTimerHandler(void)
|
||||
{
|
||||
if (Utility::GetTime() - 60 > m_Seen)
|
||||
Disconnect();
|
||||
}
|
||||
|
|
|
@ -72,6 +72,7 @@ private:
|
|||
ConnectionRole m_Role;
|
||||
double m_Seen;
|
||||
double m_NextHeartbeat;
|
||||
Timer::Ptr m_TimeoutTimer;
|
||||
|
||||
StreamReadContext m_Context;
|
||||
|
||||
|
@ -80,6 +81,8 @@ private:
|
|||
bool ProcessMessage(void);
|
||||
void DataAvailableHandler(void);
|
||||
void SendMessageSync(const Dictionary::Ptr& request);
|
||||
|
||||
void TimeoutTimerHandler(void);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue