Different C4QueryObservers share the same C4QueryEnumerator

Description

Different C4QueryObservers of the same C4Query are sharing the same C4QueryEnumerator when a change is notified. This is causing a problem that when both observers want to iterate over the enumerator. This issue is currently impact CBL-C as CBL-C is using C4QueryObserver for the LiveQuery feature.

Activity

Show:

Jianmin Zhao October 20, 2021 at 8:57 PM

Note on the current state: when there are multiple observers on the same query, the same enumerator will be passed to all the observers. The enumerator represent the result of the observed query. This does not pose any problem provided the client (the callback) of the observer does not save the position of the enumerator across thread-guarded section of code. In other words, the callback shall not assume the position of the enumerator to resume from where the last it got called.

Jens Alfke October 20, 2021 at 7:33 PM

This can be worked around by having the platform enumerator object keep track of the current row number, and call `seek` on the C4Query::Enumerator before reading the results. (With suitable locking of course.)

Pasin Suriyentrakorn October 14, 2021 at 4:51 AM
Edited

In my opinion, adding multiple observers is not common. We could add this to the known issues and fix it in Helium. 

Pasin Suriyentrakorn October 14, 2021 at 4:42 AM

 

Unit Test:

 

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Story Points

Components

Sprint

Fix versions

Affects versions

Priority

Instabug

Open Instabug

PagerDuty

Sentry

Zendesk Support

Created October 14, 2021 at 4:41 AM
Updated August 31, 2024 at 10:54 AM
Resolved October 21, 2021 at 8:07 PM
Instabug