Fix deadlock in TlsStream::Close

fixes #10235
This commit is contained in:
Gunnar Beutner 2015-09-29 10:31:16 +02:00
parent 8b1a262086
commit ca960a0c1a
4 changed files with 15 additions and 11 deletions

View File

@ -166,10 +166,12 @@ void SocketEvents::WakeUpThread(bool wait)
l_SocketIOFDChanged = true;
(void) send(l_SocketIOEventFDs[1], "T", 1, 0);
while (l_SocketIOFDChanged) {
(void) send(l_SocketIOEventFDs[1], "T", 1, 0);
while (l_SocketIOFDChanged)
l_SocketIOCV.wait(lock);
boost::system_time const timeout = boost::get_system_time() + boost::posix_time::milliseconds(50);
l_SocketIOCV.timed_wait(lock, timeout);
}
}
} else {
(void) send(l_SocketIOEventFDs[1], "T", 1, 0);

View File

@ -22,7 +22,7 @@
using namespace icinga;
void Stream::RegisterDataHandler(const boost::function<void(void)>& handler)
void Stream::RegisterDataHandler(const boost::function<void(const Stream::Ptr&)>& handler)
{
if (SupportsWaiting())
OnDataAvailable.connect(handler);
@ -42,7 +42,7 @@ bool Stream::IsDataAvailable(void) const
void Stream::SignalDataAvailable(void)
{
OnDataAvailable();
OnDataAvailable(this);
{
boost::mutex::scoped_lock lock(m_Mutex);

View File

@ -114,7 +114,7 @@ public:
virtual bool IsDataAvailable(void) const;
void RegisterDataHandler(const boost::function<void(void)>& handler);
void RegisterDataHandler(const boost::function<void(const Stream::Ptr&)>& handler);
StreamReadStatus ReadLine(String *line, StreamReadContext& context, bool may_wait = false);
@ -122,7 +122,7 @@ protected:
void SignalDataAvailable(void);
private:
boost::signals2::signal<void(void)> OnDataAvailable;
boost::signals2::signal<void(const Stream::Ptr&)> OnDataAvailable;
boost::mutex m_Mutex;
boost::condition_variable m_CV;

View File

@ -184,10 +184,12 @@ void TlsStream::OnEvent(int revents)
if (rc > 0) {
m_CurrentAction = TlsActionNone;
if (m_SendQ->GetAvailableBytes() > 0)
ChangeEvents(POLLIN|POLLOUT);
else
ChangeEvents(POLLIN);
if (!m_Eof) {
if (m_SendQ->GetAvailableBytes() > 0)
ChangeEvents(POLLIN|POLLOUT);
else
ChangeEvents(POLLIN);
}
lock.unlock();