]> granicus.if.org Git - icinga2/commitdiff
Ensure that API/JSON-RPC messages in the same session are processed and not stalled
authorMichael Friedrich <michael.friedrich@icinga.com>
Mon, 29 Oct 2018 11:57:24 +0000 (12:57 +0100)
committerMichael Friedrich <michael.friedrich@icinga.com>
Mon, 12 Nov 2018 16:07:38 +0000 (17:07 +0100)
This basically drops the "corked" implementation which just stalled the
TLS IO polling after some requests. If you need sort of rate limiting
for these events, use an external TLS proxy which terminates that in front
of Icinga.

fixes #6635

lib/base/stream.cpp
lib/base/stream.hpp
lib/base/tlsstream.cpp
lib/base/tlsstream.hpp
lib/remote/httpserverconnection.cpp
lib/remote/jsonrpcconnection.cpp

index 8e1258d7588c5b932747d745b655296532fc1af8..f41bc52a2c11404118f57f2de219b0253d207426 100644 (file)
@@ -91,16 +91,6 @@ bool Stream::WaitForData(int timeout)
        return IsDataAvailable() || IsEof();
 }
 
-void Stream::SetCorked(bool corked)
-{
-       m_Corked = corked;
-}
-
-bool Stream::IsCorked() const
-{
-       return m_Corked;
-}
-
 static void StreamDummyCallback()
 { }
 
index 0a7bf5fd0b25bdccb5b14939ce5d5288a8ccd690..72da2ba9a0772b84053da634d473eb23bc82cece 100644 (file)
@@ -127,9 +127,6 @@ public:
        bool WaitForData();
        bool WaitForData(int timeout);
 
-       virtual void SetCorked(bool corked);
-       bool IsCorked() const;
-
        virtual bool SupportsWaiting() const;
 
        virtual bool IsDataAvailable() const;
@@ -146,8 +143,6 @@ private:
 
        boost::mutex m_Mutex;
        boost::condition_variable m_CV;
-
-       bool m_Corked{false};
 };
 
 }
index c68c729776e7bea034f467590b0868e524535c9f..c51530395fd73df8d5d5cee57767a8490e66998e 100644 (file)
@@ -153,16 +153,12 @@ void TlsStream::OnEvent(int revents)
        char buffer[64 * 1024];
 
        if (m_CurrentAction == TlsActionNone) {
-               bool corked = IsCorked();
-               if (!corked && (revents & (POLLIN | POLLERR | POLLHUP)))
+               if (revents & (POLLIN | POLLERR | POLLHUP))
                        m_CurrentAction = TlsActionRead;
                else if (m_SendQ->GetAvailableBytes() > 0 && (revents & POLLOUT))
                        m_CurrentAction = TlsActionWrite;
                else {
-                       if (corked)
-                               ChangeEvents(0);
-                       else
-                               ChangeEvents(POLLIN);
+                       ChangeEvents(POLLIN);
 
                        return;
                }
@@ -289,7 +285,7 @@ void TlsStream::OnEvent(int revents)
 
                lock.unlock();
 
-               while (!IsCorked() && m_RecvQ->IsDataAvailable() && IsHandlingEvents())
+               while (m_RecvQ->IsDataAvailable() && IsHandlingEvents())
                        SignalDataAvailable();
        }
 
@@ -428,18 +424,6 @@ bool TlsStream::IsDataAvailable() const
        return m_RecvQ->GetAvailableBytes() > 0;
 }
 
-void TlsStream::SetCorked(bool corked)
-{
-       Stream::SetCorked(corked);
-
-       boost::mutex::scoped_lock lock(m_Mutex);
-
-       if (corked)
-               m_CurrentAction = TlsActionNone;
-       else
-               ChangeEvents(POLLIN | POLLOUT);
-}
-
 Socket::Ptr TlsStream::GetSocket() const
 {
        return m_Socket;
index e58d5995d4e663fadd25b07bdf0c6738877d1b5d..8e4ceb08eb163c524102609e431610452651894d 100644 (file)
@@ -70,8 +70,6 @@ public:
        bool SupportsWaiting() const override;
        bool IsDataAvailable() const override;
 
-       void SetCorked(bool corked) override;
-
        bool IsVerifyOK() const;
        String GetVerifyError() const;
 
index 81ea16b95df2c287e475afa90b2123845d8d5cdd..4f619d2f176cf87057321bfbf10857c5321db873 100644 (file)
@@ -344,7 +344,6 @@ void HttpServerConnection::ProcessMessageAsync(HttpRequest& request, HttpRespons
 
        response.Finish();
        m_PendingRequests--;
-       m_Stream->SetCorked(false);
 }
 
 void HttpServerConnection::DataAvailableHandler()
@@ -354,8 +353,6 @@ void HttpServerConnection::DataAvailableHandler()
        if (!m_Stream->IsEof()) {
                boost::recursive_mutex::scoped_lock lock(m_DataHandlerMutex);
 
-               m_Stream->SetCorked(true);
-
                try {
                        while (ProcessMessage())
                                ; /* empty loop body */
@@ -366,8 +363,6 @@ void HttpServerConnection::DataAvailableHandler()
                        close = true;
                }
 
-               m_RequestQueue.Enqueue(std::bind(&Stream::SetCorked, m_Stream, false));
-
                /* Request finished, decide whether to explicitly close the connection. */
                if (m_CurrentRequest.ProtocolVersion == HttpVersion10 ||
                        m_CurrentRequest.Headers->Get("connection") == "close") {
index 099d28723d43e7685982d6c0ab78e96ee6162e87..b9a9ceee2a2dcf71f519ed5f6c5abdf4fd3502f3 100644 (file)
@@ -276,8 +276,6 @@ void JsonRpcConnection::DataAvailableHandler()
        if (!m_Stream->IsEof()) {
                boost::mutex::scoped_lock lock(m_DataHandlerMutex);
 
-               m_Stream->SetCorked(true);
-
                try {
                        while (ProcessMessage())
                                ; /* empty loop body */
@@ -290,8 +288,6 @@ void JsonRpcConnection::DataAvailableHandler()
 
                        return;
                }
-
-               l_JsonRpcConnectionWorkQueues[m_ID % l_JsonRpcConnectionWorkQueueCount].Enqueue(std::bind(&Stream::SetCorked, m_Stream, false));
        } else
                close = true;