Another attempt at fixing the API deadlock

fixes #6617
This commit is contained in:
Gunnar Beutner 2014-07-01 09:38:22 +02:00
parent 8b1579381e
commit 65e69fcd37
3 changed files with 19 additions and 0 deletions

View File

@ -65,6 +65,17 @@ ConnectionRole ApiClient::GetRole(void) const
}
void ApiClient::SendMessage(const Dictionary::Ptr& message)
{
if (m_WriteQueue.GetLength() > 5000) {
Log(LogWarning, "remote", "Closing connection for API identity '" + m_Identity + "': Too many queued messages.");
Disconnect();
return;
}
m_WriteQueue.Enqueue(boost::bind(&ApiClient::SendMessageSync, this, message));
}
void ApiClient::SendMessageSync(const Dictionary::Ptr& message)
{
try {
ObjectLock olock(m_Stream);

View File

@ -23,6 +23,7 @@
#include "remote/endpoint.hpp"
#include "base/stream.hpp"
#include "base/timer.hpp"
#include "base/workqueue.hpp"
#include "remote/i2-remote.hpp"
namespace icinga
@ -64,8 +65,11 @@ private:
ConnectionRole m_Role;
double m_Seen;
WorkQueue m_WriteQueue;
bool ProcessMessage(void);
void MessageThreadProc(void);
void SendMessageSync(const Dictionary::Ptr& request);
};
}

View File

@ -364,6 +364,10 @@ void ApiListener::ApiTimerHandler(void)
if (endpoint->GetHost().IsEmpty() || endpoint->GetPort().IsEmpty())
continue;
/* don't try to connect if there's already a connection attempt */
if (endpoint->GetConnecting())
continue;
Utility::QueueAsyncCallback(boost::bind(&ApiListener::AddConnection, this, endpoint));
}
}