Skip to content

Commit 20a51de

Browse files
author
Raphael Dumusc
committed
Fixed unit test deadlock due to incorrect execption handling
This bug was introduced in BlueBrain#177 and could result in the global QThreadPool threads being locked forever.
1 parent 802d086 commit 20a51de

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

deflect/ImageSegmenter.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,25 @@ bool ImageSegmenter::_generateJpeg(const ImageWrapper& image,
124124
// Note: Qt insists that sending (by calling handler()) should happen
125125
// exclusively from the QThread where the socket lives. Sending from the
126126
// worker threads triggers a qWarning.
127-
bool result = true;
128-
for (size_t i = 0; i < segments.size(); ++i)
129-
if (!handler(_sendQueue.dequeue()))
130-
result = false;
131-
return result;
127+
size_t i = 0;
128+
try
129+
{
130+
bool result = true;
131+
for (; i < segments.size(); ++i)
132+
if (!handler(_sendQueue.dequeue()))
133+
result = false;
134+
return result;
135+
}
136+
catch (...)
137+
{
138+
// Wait for remaining threaded operations to finish, without calling the
139+
// handler. Otherwise the remaining threads may wait forever leading to
140+
// a deadlock in QApplication destructor.
141+
++i;
142+
for (; i < segments.size(); ++i)
143+
_sendQueue.dequeue();
144+
std::rethrow_exception(std::current_exception());
145+
}
132146
#else
133147
static bool first = true;
134148
if (first)

0 commit comments

Comments
 (0)