Bug 305685

Summary: nepomuk filewatchservice crashes randomly with assertion failure
Product: nepomuk Reporter: Mathias Tillman <master.homer>
Component: filewatchAssignee: Nepomuk Bugs Coordination <nepomuk-bugs>
Status: RESOLVED FIXED    
Severity: crash    
Priority: NOR    
Version: 4.9   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In:

Description Mathias Tillman 2012-08-23 21:00:34 UTC
The nepomuk filewatch service seems to randomly crash for me, I can't say since when as I have had it disabled for some time (for performance reasons).

Reproducible: Always

Steps to Reproduce:
1. Run nepomukservicestub nepomukfilewatch from a shell
2. Wait for a few seconds
Actual Results:  
Crashes with the assertion failure:
ASSERT: "!isEmpty()" in file /usr/include/qt4/QtCore/qlist.h, line 282

Expected Results:  
It shouldn't crash.

Backtrace:
ASSERT: "!isEmpty()" in file /usr/include/qt4/QtCore/qlist.h, line 282

Program received signal SIGABRT, Aborted.
0x00007ffff5b2d445 in __GI_raise (sig=<optimised out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
64      ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  0x00007ffff5b2d445 in __GI_raise (sig=<optimised out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1  0x00007ffff5b30bab in __GI_abort () at abort.c:91
#2  0x00007ffff797950b in qt_message_output (msgType=<optimised out>, buf=0x8bc378 "ASSERT: \"!isEmpty()\" in file /usr/include/qt4/QtCore/qlist.h, line 282") at global/qglobal.cpp:2276
#3  0x00007ffff79798bf in qt_message(QtMsgType, const char *, typedef __va_list_tag __va_list_tag *) (msgType=QtFatalMsg, msg=0x7ffff7ae6ae8 "ASSERT: \"%s\" in file %s, line %d", ap=0x7fffffffcd28) at global/qglobal.cpp:2322
#4  0x00007ffff7979a64 in qFatal (msg=<optimised out>) at global/qglobal.cpp:2505
#5  0x00007fffe72cab58 in QList<QDirIterator*>::first (this=0x820eb8) at /usr/include/qt4/QtCore/qlist.h:282
#6  0x00007fffe72ca00c in QList<QDirIterator*>::front (this=0x820eb8) at /usr/include/qt4/QtCore/qlist.h:298
#7  0x00007fffe72c94a3 in KInotify::Private::_k_addWatches (this=0x820ea0) at /home/homer/Development/Linux/Projects/nepomuk-core/services/filewatch/kinotify.cpp:148
#8  0x00007fffe72c847b in KInotify::qt_static_metacall (_o=0x820de0, _c=QMetaObject::InvokeMetaMethod, _id=15, _a=0x200b8b0) at /home/homer/Development/Linux/Projects/nepomuk-core/build/services/filewatch/kinotify.moc:96
#9  0x00007ffff7a9c446 in QObject::event (this=0x820de0, e=<optimised out>) at kernel/qobject.cpp:1195
#10 0x00007ffff637f894 in notify_helper (e=0x20b78f0, receiver=0x820de0, this=0x63f930) at kernel/qapplication.cpp:4559
#11 QApplicationPrivate::notify_helper (this=0x63f930, receiver=0x820de0, e=0x20b78f0) at kernel/qapplication.cpp:4531
#12 0x00007ffff6384713 in QApplication::notify (this=0x7fffffffdab0, receiver=0x820de0, e=0x20b78f0) at kernel/qapplication.cpp:4420
#13 0x00007ffff7a82e9c in QCoreApplication::notifyInternal (this=0x7fffffffdab0, receiver=0x820de0, event=0x20b78f0) at kernel/qcoreapplication.cpp:876
#14 0x00007ffff7a86c6a in sendEvent (event=0x20b78f0, receiver=0x820de0) at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:231
#15 QCoreApplicationPrivate::sendPostedEvents (receiver=0x0, event_type=0, data=0x60c2b0) at kernel/qcoreapplication.cpp:1500
#16 0x00007ffff7ab1f93 in sendPostedEvents () at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:236
#17 postEventSourceDispatch (s=<optimised out>) at kernel/qeventdispatcher_glib.cpp:279
#18 0x00007ffff5009d53 in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#19 0x00007ffff500a0a0 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#20 0x00007ffff500a164 in g_main_context_iteration () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#21 0x00007ffff7ab23bf in QEventDispatcherGlib::processEvents (this=0x630320, flags=...) at kernel/qeventdispatcher_glib.cpp:424
#22 0x00007ffff6427d5e in QGuiEventDispatcherGlib::processEvents (this=<optimised out>, flags=...) at kernel/qguieventdispatcher_glib.cpp:204
#23 0x00007ffff7a81c82 in QEventLoop::processEvents (this=<optimised out>, flags=...) at kernel/qeventloop.cpp:149
#24 0x00007ffff7a81ed7 in QEventLoop::exec (this=0x7fffffffd910, flags=...) at kernel/qeventloop.cpp:204
#25 0x00007ffff7a86f67 in QCoreApplication::exec () at kernel/qcoreapplication.cpp:1148
#26 0x0000000000404543 in main (argc=2, argv=0x7fffffffded8) at /home/homer/Development/Linux/Projects/nepomuk-core/servicestub/main.cpp:170

The crash seems to happen because the _k_addWatches meta call (services/filewatch/kinotify.cpp) is queued, which means that dirIterators might be empty when the queued call is actually executed, causing dirIterators.front() to throw an assertion.
A simple fix would be to either add an dirIterators.isEmpty() check to the beginning of the function, or change the _k_addWatches meta call to use Qt::DirectConnection instead of Qt::QueuedConnection.
Comment 1 Vishesh Handa 2012-08-27 10:03:22 UTC
Git commit d16e80a9e4ad6e947f5618e05e33d3267609a0dd by Vishesh Handa.
Committed on 27/08/2012 at 11:19.
Pushed by vhanda into branch 'KDE/4.9'.

kinotify: Check if the dirIterators list is empty before iterating

M  +1    -1    services/filewatch/kinotify.cpp

http://commits.kde.org/nepomuk-core/d16e80a9e4ad6e947f5618e05e33d3267609a0dd