From cef5191d44cc6d71e08f959b1ddd9a2a6d01ecea Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 11 Mar 2015 12:53:43 +0100 Subject: [PATCH] Fix timeout problem with API heartbeat messages fixes #8672 --- lib/remote/apiclient-heartbeat.cpp | 6 ++++-- lib/remote/apiclient.cpp | 5 ++++- lib/remote/apiclient.hpp | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/remote/apiclient-heartbeat.cpp b/lib/remote/apiclient-heartbeat.cpp index 066a61026..bd7aad9f8 100644 --- a/lib/remote/apiclient-heartbeat.cpp +++ b/lib/remote/apiclient-heartbeat.cpp @@ -65,7 +65,7 @@ void ApiClient::HeartbeatTimerHandler(void) request->Set("method", "event::Heartbeat"); Dictionary::Ptr params = new Dictionary(); - params->Set("timeout", 30); + params->Set("timeout", 120); request->Set("params", params); @@ -78,8 +78,10 @@ Value ApiClient::HeartbeatAPIHandler(const MessageOrigin& origin, const Dictiona { Value vtimeout = params->Get("timeout"); - if (!vtimeout.IsEmpty()) + if (!vtimeout.IsEmpty()) { origin.FromClient->m_NextHeartbeat = Utility::GetTime() + vtimeout; + origin.FromClient->m_HeartbeatTimeout = vtimeout; + } return Empty; } diff --git a/lib/remote/apiclient.cpp b/lib/remote/apiclient.cpp index da4d51eb1..b5662433e 100644 --- a/lib/remote/apiclient.cpp +++ b/lib/remote/apiclient.cpp @@ -40,7 +40,7 @@ static Timer::Ptr l_ApiClientTimeoutTimer; ApiClient::ApiClient(const String& identity, bool authenticated, const TlsStream::Ptr& stream, ConnectionRole role) : m_Identity(identity), m_Authenticated(authenticated), m_Stream(stream), m_Role(role), m_Seen(Utility::GetTime()), - m_NextHeartbeat(0), m_Context(false) + m_NextHeartbeat(0), m_HeartbeatTimeout(0), m_Context(false) { boost::call_once(l_ApiClientOnceFlag, &ApiClient::StaticInitialize); @@ -136,6 +136,9 @@ bool ApiClient::ProcessMessage(void) m_Seen = Utility::GetTime(); + if (m_HeartbeatTimeout != 0) + m_NextHeartbeat = Utility::GetTime() + m_HeartbeatTimeout; + if (m_Endpoint && message->Contains("ts")) { double ts = message->Get("ts"); diff --git a/lib/remote/apiclient.hpp b/lib/remote/apiclient.hpp index b65efdcc8..80199f1c4 100644 --- a/lib/remote/apiclient.hpp +++ b/lib/remote/apiclient.hpp @@ -72,6 +72,7 @@ private: ConnectionRole m_Role; double m_Seen; double m_NextHeartbeat; + double m_HeartbeatTimeout; Timer::Ptr m_TimeoutTimer; StreamReadContext m_Context;