Something weird is happening with a document change listener - I’m wondering if anyone has some guidance.
I have a view that, when it is displayed, has a set of data it watches and reacts to.
There is one core document, and also a set of other document.
I used to use 2 queries with a change listener on each. That was fine.
Since one of the queries just watches a single document (a hangover from v1), I thought it made sense to switch that to a db.AddDocumentChangeListener. What I’m finding is that rarely (during long running automated tests), I am occasionally getting a failure when I close the view and cleanup the listeners.
18:27:31.050618| ERROR: Assertion failed: i != observers.end() (/Users/jenkins/jenkins/workspace/couchbase-lite-core-macosx/couchbase-lite-core/LiteCore/Database/SequenceTracker.cc:296, in removeDocChangeNotifier)
0 libLiteCore.dylib libLiteCore.dylib + 57392
1 libLiteCore.dylib c4docobs_free + 74
2 ??? 0x0 + 377316445
3 ??? 0x0 + 234612243
4 ??? 0x0 + 327917324
5 ??? 0x0 + 327916707
6 ??? 0x0 + 218871532
...
at <unknown> <0xffffffff>
at (wrapper managed-to-native) LiteCore.Interop.Native.c4docobs_free (LiteCore.Interop.C4DocumentObserver*) [0x00009] in <78dfe9efed564df89e9ff941d2f5e0b3>:0
at LiteCore.Interop.LiteCoreImpl.c4docobs_free (LiteCore.Interop.C4DocumentObserver*) [0x00000] in C:\Jenkins\workspace\couchbase-lite-net-edition-build\couchbase-lite-net-ee\couchbase-lite-net\src\LiteCore\src\LiteCore.Shared\Interop\LiteCore_impl.cs:150
at Couchbase.Lite.Interop.Native.c4docobs_free (LiteCore.Interop.C4DocumentObserver*) [0x00000] in C:\Jenkins\workspace\couchbase-lite-net-edition-build\couchbase-lite-net-ee\couchbase-lite-net\src\LiteCore\src\LiteCore.Shared\Interop\LiteCore_shell.cs:152
at Couchbase.Lite.Database/<>c__DisplayClass72_0.<RemoveChangeListener>b__0 () [0x000be] in C:\Jenkins\workspace\couchbase-lite-net-edition-build\couchbase-lite-net-ee\couchbase-lite-net\src\Couchbase.Lite.Shared\API\Database\Database.cs:776
at Couchbase.Lite.Support.ThreadSafety.DoLocked (System.Action) [0x00011] in C:\Jenkins\workspace\couchbase-lite-net-edition-build\couchbase-lite-net-ee\couchbase-lite-net\src\Couchbase.Lite.Shared\Support\ThreadSafety.cs:39
at Couchbase.Lite.Database.RemoveChangeListener (Couchbase.Lite.ListenerToken) [0x00014] in C:\Jenkins\workspace\couchbase-lite-net-edition-build\couchbase-lite-net-ee\couchbase-lite-net\src\Couchbase.Lite.Shared\API\Database\Database.cs:760
at AppleLibrary.SharedNoteController.StopWatchers () [0x00067] in /Users/Paul/Dev/AppleLibrary/SharedNoteController.cs:165
...
The lines in question are below.
Setting up the listener:
docHandlerToken = database.AddDocumentChangeListener(doc_id, UpdateDocument);
docHandlerActive = true;
Removing the listener
if (docHandlerActive)
try
{
docHandlerActive = false;
database.RemoveChangeListener(docHandlerToken);
}
catch (Exception e)
{
log.Error(e, "Exception removing doc change listener");
}
It seems that the document handler token is getting invalidated.
What could cause invalidation of a handler token? How can I test for an invalidated change listener? I can’t see an API for that.
Thanks for any advice you can give.
Paul.