Prevent EntityListCache from causing endless loop

Review Request #111718 - Created July 26, 2013 and submitted

Daniel Vrátil
kdepimlibs, release-team
Calling ensureCached() can cause the cache and Monitor to end up in an endless loop.

In situation, that there are items 1,2,4,5 and 6 in the cache, calling ensureCached(1,2,3,4,5) will call request(3) and return false. request() internally calls shrinkCache() which removes all fetched items to make sure the cache does not grow indefinitely. After the item 3 is fetched, we end up with cache with only item 3. Monitor will then again call ensureCached(1,2,3,4,5), which will call request(1,2,4,5) which in return calls shrinkCache(), which will remove the item 3 and after fetched is finished the cache only contains items 1,2,4 and 5. This way the cache ends up in an endless loop because it will never contain all items that Monitor requested.

This patch prevents shrinkCache() from removing items that are part of the ensureCached() request.

I would like to get this patch to 4.11, because it's not that difficult to trigger this bug and in such case you end up with Akonadi resource going nuts (and not processing any further requests)

This implementation is still not optimal, because meanwhile the Monitor can call ensureCached(7,8,9), which will cause (1,2,4,5) to be removed from cache anyway, so it can take several tries for EntityListCache to retrieve the entire set (1,2,3,4,5). However now it's guaranteed that at some point the cache will succeed. We can rethink (and maybe remove) the cache when server-side recording is implemented.

Volker Krause
Albert Astals Cid
Commit Hook
Daniel Vrátil
Review request changed

Status: Closed (submitted)