Change feed _removed flag causing issues for a new replication

Hello

My pull Replicator seems to be getting stuck trying to deal with the _removed flag in a fairly common scenario we meet involving users and their channels.

The scenario is caused by a document being removed from my user’s assigned channels and then at a later stage us clearing/removing the user’s local database and starting the replication from scratch.

In this scenario, there is no local document that needs to be removed, seeing as the document is never downloaded in the first place due to standard channel filtering. During replication the Replicator throws an error : “Got error NotFound” where it’s trying to retrieve the specific revision of the document where the channel was removed from the document.
This user no longer has access to this document (channel permissions) so the server throwing an error is correct but I’m questioning why its being requested at all.

So it looks like the replicator is trying to download the document in order to remove it??

Am I misunderstanding something? Surely the document shouldn’t need to be pulled just in order to delete it. Is there a workaround here? Is the problem in the handling of the flag or in the flag being sent at all in the changes feed for a fresh replication?

I see you tagged this with .NET so I went ahead and tried to reproduce this by doing the following:

  1. Setting up sync gateway with a user who only has access to a channel called “test”
  2. Syncing a document and calling channel() on it in the sync function to add it to the “test” channel
  3. Syncing some more documents into no channel just to add some noise
  4. Adding a revision on the document in step 2 that causes it not to receive a channel() call and syncing it as well.

I didn’t notice any errors or things getting stuck. I saw this line in the Sync Gateway log

Cache: getCachedChanges(“test”, {2 0 0}) → 0 changes valid from #1

Which indicates that there are no documents for the user to pull. I think there is something different in your setup but could you help me figure out what it is? For what it’s worth, this is tested with Couchbase Lite built from commit ac8b75a and Sync Gateway 1.1

We’re using Xamarin, the .NET sdk 1.0.4 and sync gateway 1.0.4.
I’ll try get a repeatable example together this weekend.

I just wanted to confirm that you cleared the local db after step 4?

Ah yes, after step 4, I clear the local DB and start a sync from scratch. After that I get the message in question.