.Net P2P delete document not replicating

I’ve been looking into using CBL as an on-disk cache with a very low overhead for my microservice application. As part of this I want to keep two databases across two services in sync. For now I have been testing CBL with simple Windows console applications, and I have successfully gotten two apps to talk to each other when creating documents. My current problem is that I can’t seem to get a document delete function to replicate from the first app to the second.

I have the following 2 programs:

What’s weird is that I can replicate a delete from CouchbaseLite2 to CouchbaseLite1, but not vice versa. Doing so gives me the following log (from CouchbaseLite2):

2017-04-26 20:15:42,171|INFO |CHANGE TRACKER (ChangeTracker)|SocketChangeTracker[app1] [Couchbase Lite .NET Microsoft Windows 7 Enterprise/x64 1.4.0: Version=c2ddc0c]
2017-04-26 20:15:42,178|DEBUG|CHANGE TRACKER (ChangeTracker)|SocketChangeTracker[app1]
2017-04-26 20:15:42,180|DEBUG|CHANGE TRACKER (OneShotOrLongPollLogic)|Couchbase.Lite.Internal.OneShotOrLongPollLogic
2017-04-26 20:15:42,181|DEBUG|CHANGE TRACKER (SocketChangeTracker)|SocketChangeTracker[app1]
2017-04-26 20:15:42,182|INFO |SYNC (Puller)|1 4 0 1 Puller a13e5e9e-7933-4c67-9f11-a4adb22b6a94
2017-04-26 20:15:42,193|DEBUG|CHANGE TRACKER (SocketChangeTracker)|http://127.0.0.1:59840/app1/_changes?feed=longpoll&heartbeat=300000&style=all_docs&since=4
2017-04-26 20:15:42,236|INFO |SYNC (Puller)|Puller a13e5e9e-7933-4c67-9f11-a4adb22b6a94 error pulling remote revision
System.AggregateException: One or more errors occurred. ---> Couchbase.Lite.HttpResponseException: Exception of type 'Couchbase.Lite.HttpResponseException' was thrown.
   at Couchbase.Lite.Util.TransientErrorRetryHandler.HandleTransientErrors(Task`1 request, Object state)
   at Couchbase.Lite.Util.TransientErrorRetryHandler.<ResendHandler>c__AnonStorey0.<>m__0(Task`1 t)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
   at Couchbase.Lite.CouchbaseLiteHttpClient.<SendAsync>c__AnonStorey2.<>m__1(Task`1 t)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
---> (Inner Exception #0) [HttpResponseException: StatusCode = NotFound]<---

2017-04-26 20:15:42,247|INFO |SYNC (Replication)|Error set during replication (application may continue)
System.AggregateException: One or more errors occurred. ---> Couchbase.Lite.HttpResponseException: Exception of type 'Couchbase.Lite.HttpResponseException' was thrown.
   at Couchbase.Lite.Util.TransientErrorRetryHandler.HandleTransientErrors(Task`1 request, Object state)
   at Couchbase.Lite.Util.TransientErrorRetryHandler.<ResendHandler>c__AnonStorey0.<>m__0(Task`1 t)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   --- End of inner exception stack trace ---
   at Couchbase.Lite.CouchbaseLiteHttpClient.<SendAsync>c__AnonStorey2.<>m__1(Task`1 t)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
---> (Inner Exception #0) [HttpResponseException: StatusCode = NotFound]<---

Note: I have already authorized the URL as an admin for Windows (I was getting a different error before that)

There should be more information on what went wrong in the logs of CouchbaseLite1. I can’t tell what is happening at first glance, and the description mixed with those log entries is very strange.

The only reason for a 404 on the changes feed is that the database does not exist on the other side, but it obviously does if you are replicating creations to and from it. My sneaking suspicion says that you are deleting the database on CouchbaseLite1 accidentally somehow. That would cause this behavior, but I don’t see any of that in the code you provided so I’m left scratching my head.

I can’t attach the logs directly since my account is too new, but here’s the pastebin of the full logs:

CouchbaseLite1:
https://pastebin.com/TL1bg3BT

CouchbaseLite2:
https://pastebin.com/qtCaHP4n

Any log lines with the tag "MAIN (Main)" are actually logs that I put in myself to see what’s in the db. I can also rerun the test with whatever log settings you’d like to see since this is an easily reproducible problem for me.

I don’t see any logs in the listener that indicate that it returned a 404. Sometimes when I start up something like this, the last process didn’t get killed and it is actually that one that is fielding requests. That is something to look into. It also looks like the logs are getting cut off. There should be messages at INFO in router indicating the HTTP status code for each request.

I have put the code I’m running into a quick github repo and tried it on my home computer and got the same results. Would you mind taking a look?

CouchbaseLite1

CouchbaseLite2

I fixed the logging on my test apps, when trying to make a quick log4net adapter I didn’t properly format the message. Looking at it now it seems like CouchbaseLite1 is returning a 404 because I deleted the entry, and gave CouchbaseLite2 the new revision, however then CouchbaseLite2 is trying to query CouchbaseLite1 for that revision, in which CouchbaseLite1 returns:

{
  "status": 404,
  "error": "not_found",
  "reason": "deleted"
}

CouchbaseLite_Delete_Error_Logs.zip (5.5 KB)

Indeed this looks like a difference in the way the P2P handles deletes vs the way Sync Gateway handles deletes. That seems to be confusing the puller. I’ll need to speak to the team about how to handle this situation. I’m out of the office until next week but I will see what I can do then.

P.S. You can try a “push-only” solution in the meantime if you like in which you just set up push replications on each side.

1 Like

Hi borrrden, has there been any update on this? Should I open an issue to GitHub instead?

I already filed an issue, but there hasn’t been any work done on it. https://github.com/couchbase/couchbase-lite-net/issues/850 2.0 work is taking priority over 1.x at the moment so that is why there is so little progress. We don’t have a timetable for 1.4.1 and the thing that will affect it is whether or not we need to make it for enterprise customers.

If you want to try to make the fix yourself I can give you some advice along the way though! :slight_smile:

Hmmm… that is tempting. If I find the free time I may contact you about that later. One question about 2.0: Are y’all going to support a P2P connection like you do currently?

For 2.0, we are still looking at at our P2P support plan and timetable. We will have more details shortly.