summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-08-17 12:04:46 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-08-17 12:10:36 +0200
commitf7c37ede99d02a91738f38505922dd331be0ad96 (patch)
tree8ca9bf0a0be4d9b9339bd97bcf02ed287078909a
parent3c43330dddcd71c3251a55d5211edf506d3ec767 (diff)
downloadsink-f7c37ede99d02a91738f38505922dd331be0ad96.tar.gz
sink-f7c37ede99d02a91738f38505922dd331be0ad96.zip
Fixed possible deadlock if we get a debug message in the wrong moment
This was the problematic backtrace (the qsettigns lockfile resulted in a message that tried to acquire the lock again. Thread 1 (Thread 0x7f00417aee00 (LWP 530)): 0 0x00007f003eb9cae9 in syscall () from /lib64/libc.so.6 1 0x00007f003f85d22d in QBasicMutex::lockInternal() () from /lib64/libQt5Core.so.5 2 0x00007f0040ebce51 in QMutexLocker::QMutexLocker (this=0x7ffdb83e4678, m=0x7f004175ff40 <(anonymous namespace)::Q_QGS_sDebugAreaCollector::innerFunction()::holder>) at /usr/include/qt5/QtCore/qmutex.h:206 3 0x00007f00410ab681 in DebugAreaCollector::add (this=0x7f004175ff40 <(anonymous namespace)::Q_QGS_sDebugAreaCollector::innerFunction()::holder>, area="caldavresource.default") at /src/sink/common/log.cpp:269 4 0x00007f00410a6f4b in collectDebugArea (debugArea="caldavresource.default") at /src/sink/common/log.cpp:296 5 0x00007f00410a5b44 in Sink::Log::debugStream (debugLevel=Sink::Log::Warning, line=0, file=0x0, function=0x0, debugArea=0x7f003fabdfa0 "default", debugComponent=0x0) at /src/sink/common/log.cpp:379 6 0x0000000000406d8d in qtMessageHandler (type=QtWarningMsg, context=..., msg="Could not remove our own lock file \"/home/developer/.qttest/share/sink/debugAreas.ini.lock\" maybe permissions changed meanwhile?") at /src/sink/synchronizer/main.cpp:162 7 0x00007f003f8509be in qt_message_print(QtMsgType, QMessageLogContext const&, QString const&) () from /lib64/libQt5Core.so.5 8 0x00007f003f8529ec in qt_message_output(QtMsgType, QMessageLogContext const&, QString const&) () from /lib64/libQt5Core.so.5 9 0x00007f003f93eb40 in QDebug::~QDebug() () from /lib64/libQt5Core.so.5 10 0x00007f003f9b55ba in QLockFile::unlock() () from /lib64/libQt5Core.so.5 11 0x00007f003f959ffd in QLockFile::~QLockFile() () from /lib64/libQt5Core.so.5 12 0x00007f003f98f4e3 in QConfFileSettingsPrivate::syncConfFile(QConfFile*) () from /lib64/libQt5Core.so.5 13 0x00007f003f98fcee in QConfFileSettingsPrivate::sync() () from /lib64/libQt5Core.so.5 14 0x00007f003f985df9 in QSettings::~QSettings() () from /lib64/libQt5Core.so.5 15 0x00007f00410a8cd1 in QtSharedPointer::ExternalRefCountWithContiguousData<QSettings>::deleter (self=0x17e2890) at /usr/include/qt5/QtCore/qsharedpointer_impl.h:255 16 0x00007f0040e7092b in QtSharedPointer::ExternalRefCountData::destroy (this=0x17e2890) at /usr/include/qt5/QtCore/qsharedpointer_impl.h:157 17 0x00007f00410a8e2d in QSharedPointer<QSettings>::deref (dd=0x17e2890) at /usr/include/qt5/QtCore/qsharedpointer_impl.h:461 18 0x00007f00410a8de9 in QSharedPointer<QSettings>::deref (this=0x7ffdb83e4ea8) at /usr/include/qt5/QtCore/qsharedpointer_impl.h:456 19 0x00007f00410a8b75 in QSharedPointer<QSettings>::~QSharedPointer (this=0x7ffdb83e4ea8) at /usr/include/qt5/QtCore/qsharedpointer_impl.h:313 20 0x00007f00410a9f23 in DebugAreaCollector::~DebugAreaCollector (this=0x7f004175ff40 <(anonymous namespace)::Q_QGS_sDebugAreaCollector::innerFunction()::holder>) at /src/sink/common/log.cpp:264 21 0x00007f00410a76b9 in (anonymous namespace)::Q_QGS_sDebugAreaCollector::innerFunction()::Holder::~Holder() (this=0x7f004175ff40 <(anonymous namespace)::Q_QGS_sDebugAreaCollector::innerFunction()::holder>) at /src/sink/common/log.cpp:283 22 0x00007f003eae172c in __run_exit_handlers () from /lib64/libc.so.6 23 0x00007f003eae185c in exit () from /lib64/libc.so.6 24 0x00007f003eacb252 in __libc_start_main () from /lib64/libc.so.6 25 0x00000000004064da in _start () Closes https://phabricator.kde.org/T9435
-rw-r--r--common/log.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/common/log.cpp b/common/log.cpp
index 5156a23..e5ed29b 100644
--- a/common/log.cpp
+++ b/common/log.cpp
@@ -253,14 +253,22 @@ class DebugAreaCollector {
253public: 253public:
254 DebugAreaCollector() 254 DebugAreaCollector()
255 { 255 {
256 QMutexLocker locker(&mutex); 256 //This call can potentially print a log message (if we fail to remove the qsettings lockfile), which would result in a deadlock if we locked over all of it.
257 mDebugAreas = debugAreasConfig()->value("areas").value<QString>().split(';').toSet(); 257 const auto areas = debugAreasConfig()->value("areas").value<QString>().split(';').toSet();
258 {
259 QMutexLocker locker(&mutex);
260 mDebugAreas = areas;
261 }
258 } 262 }
259 263
260 ~DebugAreaCollector() 264 ~DebugAreaCollector()
261 { 265 {
262 QMutexLocker locker(&mutex); 266 //This call can potentially print a log message (if we fail to remove the qsettings lockfile), which would result in a deadlock if we locked over all of it.
263 mDebugAreas += debugAreasConfig()->value("areas").value<QString>().split(';').toSet(); 267 const auto areas = debugAreasConfig()->value("areas").value<QString>().split(';').toSet();
268 {
269 QMutexLocker locker(&mutex);
270 mDebugAreas += areas;
271 }
264 debugAreasConfig()->setValue("areas", QVariant::fromValue(mDebugAreas.toList().join(';'))); 272 debugAreasConfig()->setValue("areas", QVariant::fromValue(mDebugAreas.toList().join(';')));
265 } 273 }
266 274