Document removed channel not replicated

Hi together,
I encountered an issue with replication of document channel updates.
To permit user2 access to a document of user1, I added user2 in channels property of that document (each user has its own channel). That works propertly, so user2 is able to see the document.
But if I user1 removes user2 from channels property (via Documents Update method), the update does not get replicated to user2. In the Couchbase Console I see, that the push to the remote Database was successful. But user2 still has the document in its local database where his username is present in the channels property of the document.

Sync Gateway log from where I removed the channel from the doc:
2016-03-09T16:06:00.674+01:00 HTTP: #030: POST /hamster/_revs_diff (as user1)
2016-03-09T16:06:00.754+01:00 HTTP: #031: POST /hamster/_bulk_docs (as user1)
2016-03-09T16:06:00.757+01:00 CRUD+: Invoking sync on doc “-CTLn_pvYckK9AS5WVhFC-A” rev 6-6949d5c76d180d4f1387ba2db83c2736
2016-03-09T16:06:00.757+01:00 CRUD+: Saving old revision “-CTLn_pvYckK9AS5WVhFC-A” / “5-3c694552804413e12e79e5a39531fbd8” (521 bytes)
2016-03-09T16:06:00.758+01:00 CRUD+: Backed up obsolete rev “-CTLn_pvYckK9AS5WVhFC-A”/"5-3c694552804413e12e79e5a39531fbd8"
2016-03-09T16:06:00.758+01:00 CRUD: Doc “-CTLn_pvYckK9AS5WVhFC-A” in channels "{user1}“
2016-03-09T16:06:00.758+01:00 CRUD: Stored doc “-CTLn_pvYckK9AS5WVhFC-A” / “6-6949d5c76d180d4f1387ba2db83c2736"
2016-03-09T16:06:03.662+01:00 Changes+: Notifying that “hamster” changed (keys=”{*, user1, user2}”) count=3
2016-03-09T16:06:03.662+01:00 Changes+: MultiChangesFeed: channels expand to channels.TimedSet{“user1”:channels.VbSequence{VbNo:(*uint16)(nil), Sequence:0x2}} … (to user1)
2016-03-09T16:06:03.662+01:00 Changes+: Sending seq:23 from channel user1
2016-03-09T16:06:03.662+01:00 Changes+: MultiChangesFeed sending &{Seq:23 ID:-CTLn_pvYckK9AS5WVhFC-A Deleted:false Removed:{} Doc:map[] Changes:[map[rev:6-6949d5c76d180d4f1387ba2db83c2736]] Err: allRemoved:false branched:false} (to user1)
2016-03-09T16:06:03.662+01:00 Changes: MultiChangesFeed done (to user1)
2016-03-09T16:06:03.662+01:00 Changes+: MultiChangesFeed: channels expand to channels.TimedSet{“user2”:channels.VbSequence{VbNo:(*uint16)(nil), Sequence:0x3}} … (to user2)
2016-03-09T16:06:03.662+01:00 Changes+: Sending seq:23 from channel user2
2016-03-09T16:06:03.662+01:00 Changes+: MultiChangesFeed sending &{Seq:23 ID:-CTLn_pvYckK9AS5WVhFC-A Deleted:false Removed:{user2} Doc:map[] Changes:[map[rev:6-6949d5c76d180d4f1387ba2db83c2736]] Err: allRemoved:true branched:false} (to user2)
2016-03-09T16:06:03.662+01:00 Changes: MultiChangesFeed done (to user2)
2016-03-09T16:06:03.767+01:00 HTTP: #032: POST /hamster/_changes (as user2)
2016-03-09T16:06:03.767+01:00 Changes+: Int sequence multi changes feed…
2016-03-09T16:06:03.767+01:00 Changes: MultiChangesFeed({user2}, {Since:23 Limit:500 Conflicts:true IncludeDocs:false Wait:true Continuous:false Terminator:0xc820a13f20 HeartbeatMs:300000 TimeoutMs:300000 ActiveOnly:false}) … (to user2)
2016-03-09T16:06:03.768+01:00 Changes+: MultiChangesFeed: channels expand to channels.TimedSet{“user2”:channels.VbSequence{VbNo:(*uint16)(nil), Sequence:0x3}} … (to user2)
2016-03-09T16:06:03.768+01:00 Changes+: MultiChangesFeed waiting… (to user2)
2016-03-09T16:06:03.768+01:00 Changes+: Waiting for “hamster”'s count to pass 3
2016-03-09T16:06:04.086+01:00 HTTP: #033: POST /hamster/_changes (as user1)
2016-03-09T16:06:04.086+01:00 Changes+: Int sequence multi changes feed…
2016-03-09T16:06:04.086+01:00 Changes: MultiChangesFeed({user1}, {Since:23 Limit:500 Conflicts:true IncludeDocs:false Wait:true Continuous:false Terminator:0xc820bc2300 HeartbeatMs:300000 TimeoutMs:300000 ActiveOnly:false}) … (to user1)
2016-03-09T16:06:04.086+01:00 Changes+: MultiChangesFeed: channels expand to channels.TimedSet{“user1”:channels.VbSequence{VbNo:(*uint16)(nil), Sequence:0x2}} … (to user1)
2016-03-09T16:06:04.086+01:00 Changes+: MultiChangesFeed waiting… (to user1)
2016-03-09T16:06:04.086+01:00 Changes+: Waiting for “hamster”'s count to pass 3

In prior posts I read that updating channels property should work properly.

In my Console output of my Application (on user2’s device) I saw following:

Replication: Beginning replication process…
03-09 16:25:40.469 I/mono-stdout( 1315): Replication: Beginning replication process…
Thread started: #9
Replication: Beginning replication process…
03-09 16:25:40.477 D/Mono ( 1315): [0xb9d7d200] worker starting
Replication: No local checkpoint, not getting remote one
Replication: No local checkpoint, not getting remote one
03-09 16:25:40.477 I/mono-stdout( 1315): Replication: Beginning replication process…
03-09 16:25:40.477 I/mono-stdout( 1315): Replication: No local checkpoint, not getting remote one
03-09 16:25:40.477 I/mono-stdout( 1315): Replication: No local checkpoint, not getting remote one

Could this be the problem…?

Many thanks in advance!

From your log output, this line:

2016-03-09T16:06:03.662+01:00 Changes+: MultiChangesFeed sending &{Seq:23 ID:-CTLn_pvYckK9AS5WVhFC-A Deleted:false Removed:{user2} Doc:map Changes: [map[rev:6-6949d5c76d180d4f1387ba2db83c2736]] Err: allRemoved:true branched:false} (to user2)

indicates that the latest revision of the doc is being sent to user2 with removed=true. This is the notification to user2 that they no longer have access to the doc, and is the trigger for removal on the client.

Thanks for your quick reply!

Are there situations possible when a document does not get updated on client database?

I query data from local database with the following code:

 public IEnumerable<InventoryItem> GetBorrowedItems()
    {
        // retrieve the document from the database
        var query = CouchbaseDatabase.GetDb().CreateAllDocumentsQuery();
        query.AllDocsMode = AllDocsMode.AllDocs;
        var rows = query.Run();

        List<InventoryItem> items = new List<InventoryItem>();
        foreach (var row in rows)
        {
            Document doc = row.Document;
            Debug.WriteLine("DOC name: " + doc.CurrentRevision.GetProperty("Name"));
            Debug.WriteLine("DOC channels: " + doc.CurrentRevision.GetProperty("channels"));
            Debug.WriteLine("DOC deleted: " + doc.Deleted);
            Debug.WriteLine("DOC rev: " + doc.CurrentRevisionId);
            InventoryItem item = FromDocument(doc);
            items.Add(item);
        }

        return items;
    }

Curiously, the RevisionID is still the same as in the old Document version (before I removed user2 from channels property) and user2 is still present in the channels property, I noticed while debugging with code above. In remote database there exists a newer revision where user2 has already been removed from channels property.

The log outputs from Console (Replication process) in my last posts cannot be the reason for this issue?