mirror of https://github.com/Icinga/icinga2.git
JsonRpcConnection#Disconnect(): spawn coroutine only if necessary
by checking the now atomic #m_ShuttingDown outside of it.
This commit is contained in:
parent
a51910a19b
commit
33f8ea6dcc
|
@ -188,12 +188,10 @@ void JsonRpcConnection::Disconnect()
|
||||||
{
|
{
|
||||||
namespace asio = boost::asio;
|
namespace asio = boost::asio;
|
||||||
|
|
||||||
JsonRpcConnection::Ptr keepAlive (this);
|
if (!m_ShuttingDown.exchange(true)) {
|
||||||
|
JsonRpcConnection::Ptr keepAlive (this);
|
||||||
IoEngine::SpawnCoroutine(m_IoStrand, [this, keepAlive](asio::yield_context yc) {
|
|
||||||
if (!m_ShuttingDown) {
|
|
||||||
m_ShuttingDown = true;
|
|
||||||
|
|
||||||
|
IoEngine::SpawnCoroutine(m_IoStrand, [this, keepAlive](asio::yield_context yc) {
|
||||||
Log(LogWarning, "JsonRpcConnection")
|
Log(LogWarning, "JsonRpcConnection")
|
||||||
<< "API client disconnected for identity '" << m_Identity << "'";
|
<< "API client disconnected for identity '" << m_Identity << "'";
|
||||||
|
|
||||||
|
@ -241,8 +239,8 @@ void JsonRpcConnection::Disconnect()
|
||||||
shutdownTimeout->Cancel();
|
shutdownTimeout->Cancel();
|
||||||
|
|
||||||
m_Stream->lowest_layer().shutdown(m_Stream->lowest_layer().shutdown_both, ec);
|
m_Stream->lowest_layer().shutdown(m_Stream->lowest_layer().shutdown_both, ec);
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonRpcConnection::MessageHandler(const String& jsonString)
|
void JsonRpcConnection::MessageHandler(const String& jsonString)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include "remote/i2-remote.hpp"
|
#include "remote/i2-remote.hpp"
|
||||||
#include "remote/endpoint.hpp"
|
#include "remote/endpoint.hpp"
|
||||||
|
#include "base/atomic.hpp"
|
||||||
#include "base/io-engine.hpp"
|
#include "base/io-engine.hpp"
|
||||||
#include "base/tlsstream.hpp"
|
#include "base/tlsstream.hpp"
|
||||||
#include "base/timer.hpp"
|
#include "base/timer.hpp"
|
||||||
|
@ -77,7 +78,7 @@ private:
|
||||||
std::vector<String> m_OutgoingMessagesQueue;
|
std::vector<String> m_OutgoingMessagesQueue;
|
||||||
AsioConditionVariable m_OutgoingMessagesQueued;
|
AsioConditionVariable m_OutgoingMessagesQueued;
|
||||||
AsioConditionVariable m_WriterDone;
|
AsioConditionVariable m_WriterDone;
|
||||||
bool m_ShuttingDown;
|
Atomic<bool> m_ShuttingDown;
|
||||||
boost::asio::deadline_timer m_CheckLivenessTimer, m_HeartbeatTimer;
|
boost::asio::deadline_timer m_CheckLivenessTimer, m_HeartbeatTimer;
|
||||||
|
|
||||||
JsonRpcConnection(const String& identity, bool authenticated, const Shared<AsioTlsStream>::Ptr& stream, ConnectionRole role, boost::asio::io_context& io);
|
JsonRpcConnection(const String& identity, bool authenticated, const Shared<AsioTlsStream>::Ptr& stream, ConnectionRole role, boost::asio::io_context& io);
|
||||||
|
|
Loading…
Reference in New Issue