Bug 406881 - Infinite loop in sortedPrenodes
Summary: Infinite loop in sortedPrenodes
Status: REPORTED
Alias: None
Product: korganizer
Classification: Applications
Component: incidence viewer (show other bugs)
Version: GIT (master)
Platform: Compiled Sources Linux
: NOR grave
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-25 08:30 UTC by Kevin Funk
Modified: 2019-11-16 16:48 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Funk 2019-04-25 08:30:27 UTC
STEPS TO REPRODUCE
1. Start korganizer
2. Will hang right after start

OBSERVED RESULT
Hangs in sortedPrenodes() function:


Debugging through the code with breakpoints set reveals the problem: Apparently there are nodes share the same UID(?) => In that case the while()-loop never finishes, since it's just overwriting entries in the `prenodeByUid` hash and thus does not grow.

Trace here:
```
Thread 1 "korganizer" hit Breakpoint 10, sortedPrenodes (nodes=...) at /home/kfunk/devel/src/kf5/eventviews/src/todo/incidencetreemodel.cpp:62
(gdb) c
Continuing.

Thread 1 "korganizer" hit Breakpoint 11, sortedPrenodes (nodes=...) at /home/kfunk/devel/src/kf5/eventviews/src/todo/incidencetreemodel.cpp:67
$94 = (const PreNode::Ptr &) @0x602000711010: {value = 0x604000e4f210, d = 0x6030007b0af0}
$95 = 0x606001014e78 "fe7334c6-fa08-4f8a-8f20-1bec21b68013"

Thread 1 "korganizer" hit Breakpoint 11, sortedPrenodes (nodes=...) at /home/kfunk/devel/src/kf5/eventviews/src/todo/incidencetreemodel.cpp:67
$96 = (const PreNode::Ptr &) @0x6020007111b0: {value = 0x604000e4f5d0, d = 0x6030007418b0}
$97 = 0x606001014f38 "08c6d8f3-a6d4-45a5-af6b-9c08f6cd6638"

Thread 1 "korganizer" hit Breakpoint 11, sortedPrenodes (nodes=...) at /home/kfunk/devel/src/kf5/eventviews/src/todo/incidencetreemodel.cpp:67
$98 = (const PreNode::Ptr &) @0x60200070fd30: {value = 0x604000e4f150, d = 0x6030007413d0}
$99 = 0x606001015178 "8b64756f-910d-4e63-bf23-72cfcd908ba8"

Thread 1 "korganizer" hit Breakpoint 11, sortedPrenodes (nodes=...) at /home/kfunk/devel/src/kf5/eventviews/src/todo/incidencetreemodel.cpp:67
$100 = (const PreNode::Ptr &) @0x60200070fbb0: {value = 0x604000e4f090, d = 0x6030005cc2c0}
$101 = 0x606001015298 "08c6d8f3-a6d4-45a5-af6b-9c08f6cd6638"

Thread 1 "korganizer" hit Breakpoint 11, sortedPrenodes (nodes=...) at /home/kfunk/devel/src/kf5/eventviews/src/todo/incidencetreemodel.cpp:67
$102 = (const PreNode::Ptr &) @0x60200070faf0: {value = 0x604000e4efd0, d = 0x603000741700}
$103 = 0x606001015658 "8b64756f-910d-4e63-bf23-72cfcd908ba8"

Thread 1 "korganizer" hit Breakpoint 11, sortedPrenodes (nodes=...) at /home/kfunk/devel/src/kf5/eventviews/src/todo/incidencetreemodel.cpp:67
$104 = (const PreNode::Ptr &) @0x60200070fa10: {value = 0x604000e50050, d = 0x6030007b8830}
$105 = 0x606001015238 "d1c0ce54-3b13-4a9e-b251-0fbd015ad6c4"

Thread 1 "korganizer" hit Breakpoint 11, sortedPrenodes (nodes=...) at /home/kfunk/devel/src/kf5/eventviews/src/todo/incidencetreemodel.cpp:67
$106 = (const PreNode::Ptr &) @0x60200070fab0: {value = 0x604000e4ebd0, d = 0x6030007b06d0}
$107 = 0x6060010151d8 "987bbf7f-ed3d-4b61-993f-d811ba3f12f6"

Thread 1 "korganizer" hit Breakpoint 11, sortedPrenodes (nodes=...) at /home/kfunk/devel/src/kf5/eventviews/src/todo/incidencetreemodel.cpp:67
$108 = (const PreNode::Ptr &) @0x602000710890: {value = 0x604000e54350, d = 0x603000740e60}
$109 = 0x6060010170f8 "396ab294-7401-4e14-a301-344324468d76"

Thread 1 "korganizer" hit Breakpoint 11, sortedPrenodes (nodes=...) at /home/kfunk/devel/src/kf5/eventviews/src/todo/incidencetreemodel.cpp:67
$110 = (const PreNode::Ptr &) @0x602000710630: {value = 0x604000e54310, d = 0x6030007b7b40}
$111 = 0x604000e54ce8 "libkcal-1783146074.707"
```

$101 shows that I have "08c6d8f3-a6d4-45a5-af6b-9c08f6cd6638" in there twice. Shouldn't happen I guess?

Ideas welcome!
Comment 1 Kevin Funk 2019-04-25 08:32:50 UTC
Note: Following breakpoints are relevant:

10      breakpoint     keep y   0x00007f382281b332 in sortedPrenodes(QList<QSharedPointer<PreNode> > const&) 
                                                   at /home/kfunk/devel/src/kf5/eventviews/src/todo/incidencetreemodel.cpp:62
        breakpoint already hit 3 times
11      breakpoint     keep y   0x00007f382281b428 in sortedPrenodes(QList<QSharedPointer<PreNode> > const&) 
                                                   at /home/kfunk/devel/src/kf5/eventviews/src/todo/incidencetreemodel.cpp:67
        breakpoint already hit 62 times
        p node
        p uid.toLatin1().constData()
        cont
Comment 2 Kevin Funk 2019-04-25 09:41:40 UTC
Managed to find the culprit by printing some more debug output and thereby locating the problematic calendar folder

The final fix was to clear the Akonadi cache for that particular calendar folder; I think that helped. Not sure how I got in that state to begin with.

I think that 'sortedPrenodes' should probably be more graceful for situations like this and not run into an infinite loop in any case(?)

Here's the tmp patch (just for the record):
```
diff --git a/src/todo/incidencetreemodel.cpp b/src/todo/incidencetreemodel.cpp
index c6b03d4..88dc935 100644
--- a/src/todo/incidencetreemodel.cpp
+++ b/src/todo/incidencetreemodel.cpp
@@ -59,11 +59,13 @@ static PreNode::List sortedPrenodes(const PreNode::List &nodes)
     PreNode::List remainingNodes = nodes;
 
     while (prenodeByUid.count() < count) {
+        qDebug() << "FOO: " << remainingNodes << "- prenodeByUid.count:" << prenodeByUid.count() << "- count:" << count;
         bool foundAtLeastOne = false; // this bool saves us from infinit looping if the parent doesn't exist
         for (const PreNode::Ptr &node : nodes) {
             Q_ASSERT(node);
             const QString uid = node->incidence->instanceIdentifier();
             const QString parentUid = node->incidence->relatedTo();
+            qDebug() << "  uid" << uid << "- parent uid:" << parentUid << "- desc:" << node->incidence->description() << "- summary:" << node->incidence->summary();
             if (parentUid.isEmpty()) {   // toplevel todo
                 prenodeByUid.insert(uid, node);
                 remainingNodes.removeAll(node);
```
Comment 3 Allen Winter 2019-11-16 16:48:16 UTC
@Kevin: I'm not sure if we should resolve this or not.
if there is a bug, it would see to be in Akonadi and not KOrganizer