From 60181e0abb172d3bf772d6abf96f4d80a9e73db6 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 1 Feb 2016 14:50:18 +0100 Subject: [PATCH] Fix deadlock in HttpClientConnection::DataAvailableHandler refs #11014 --- lib/remote/httpclientconnection.cpp | 30 ++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/remote/httpclientconnection.cpp b/lib/remote/httpclientconnection.cpp index 9bad381d9..84b66d420 100644 --- a/lib/remote/httpclientconnection.cpp +++ b/lib/remote/httpclientconnection.cpp @@ -137,24 +137,28 @@ bool HttpClientConnection::ProcessMessage(void) void HttpClientConnection::DataAvailableHandler(const Stream::Ptr& stream) { - boost::mutex::scoped_lock lock(m_DataHandlerMutex); - ASSERT(stream == m_Stream); - try { - while (ProcessMessage()) - ; /* empty loop body */ - } catch (const std::exception& ex) { - Log(LogWarning, "HttpClientConnection") - << "Error while reading Http response: " << DiagnosticInformation(ex); + bool close = false; - Disconnect(); - } + if (!m_Stream->IsEof()) { + boost::mutex::scoped_lock lock(m_DataHandlerMutex); - if (m_Context.Eof) { - Log(LogWarning, "HttpClientConnection", "Encountered unexpected EOF while reading Http response."); + try { + while (ProcessMessage()) + ; /* empty loop body */ + } catch (const std::exception& ex) { + Log(LogWarning, "HttpClientConnection") + << "Error while reading Http response: " << DiagnosticInformation(ex); + + close = true; + Disconnect(); + } + } else + close = true; + + if (close) m_Stream->Close(); - } } boost::shared_ptr HttpClientConnection::NewRequest(void) -- 2.40.0