Couchbase lite java replication not working

We are building a kotlin application with couchbase-lite-java-ee:2.8.3. The development environment is mac. Replication basically is not working. No documents are being pulled from sync_gateway. Below are the details.

when the replication is started with DEBUG logging enabled on ALL_DOMAINS, we are getting the logs available here.

i am not sure, but the line 20 in the logs is the following :

V/CouchbaseLite/NETWORK:WebSocketListener opened with response Response{protocol=http/1.1, code=101, message=Switching Protocols, url=http://localhost:4984/test/_blipsync}

wondering why the protocol is being switched to http.

My development setup

  1. Couchbase Server : enterprise-7.0.0-beta in docker (have tried with 6.5.0 as well but no luck with that too)
  2. Sync Gateway : enterprise -2.8.1 in docker
  3. Java : openjdk version “1.8.0_282”

The test db has just one document in it. I browsed through the <sync gateway url>/_admin/ console and as best as i can tell, everything looks normal.

Anyone has any idea as to why this could be failing? My hunch says there is some very basic networking/configuration issue with no errors to help us in the right direction.

That interpretation is not right. The log message is not indicating that the protocol is switching to http. protocol. On the contrary, what is happening is that the protocol is switching to websockets as described in RFC 6455. When replication starts up, the Couchbase lite client sends a WebSocket handshake request to the server over HTTP(s) indicating that it wants to switch to WebSocket. This is an HTTP GET request, with special headers, to the resource _blipsync relative to the database’s URL… So what you are seeing here is expected.

From logs, connection is established successfully in line 23. There is some data being exchanged (line 37-41 says that some data is being pulled- not sure which doc was pulled ). I see that the replicator is closed with 1000 (which AFAIK is normal disconnect).

There is nothing in the error logs that indicates that there is an error as far as networking goes…

If you are not seeing documents that you expect to see pulled down, then there are a number of areas to look at

  1. Check sync gateway logs and see if document is imported correctly by sync gateway. Ensure it is configured correctly per documentation
  2. Do a get on specific document Id . I do not know what your query is but maybe you are not processing query results correctly or not querying correctly
1 Like

To expand on @priya.rajagopal 's comment, this bit of the log you proved:

    V/CouchbaseLite/NETWORK:WebSocketListener is closing with code 1000, reason 
    D/CouchbaseLite/NETWORK:C4Socket.closeRequested @140564269053936: 1000()
    D/CouchbaseLite/NETWORK:C4Socket.requestClose @140564269053936: AbstractCBLWebSocket{ws://localhost:4984/test/_blipsync} #1000()
    V/CouchbaseLite/NETWORK:CBLWebSocket already closing.
    V/CouchbaseLite/NETWORK:WebSocketListener closed with code 1000, reason 
    D/CouchbaseLite/NETWORK:C4Socket.closed @140564269053936: 0
    D/CouchbaseLite/NETWORK:C4Socket.dispose @140564269053936: AbstractCBLWebSocket{ws://localhost:4984/test/_blipsync}
    D/CouchbaseLite/NETWORK:C4Socket.release @140564269053936: 0
    D/CouchbaseLite/REPLICATOR:C4Replicator.statusChangedCallback @7fd7ab533290, status:  C4ReplicatorStatus{level=0,completed=0,total=0,#docs=0,domain=0,code=0,info=0}
    I/CouchbaseLite/REPLICATOR:C4ReplicatorListener.statusChanged, context: Replicator{@0x3e6fa38a(<-),Database{@0x47f6473, name='loustooth'} => URLEndpoint{url=ws://localhost:4984/test}}, status: C4ReplicatorStatus{level=0,completed=0,total=0,#docs=0,domain=0,code=0,info=0}
    I/CouchbaseLite/REPLICATOR:Replicator{@0x3e6fa38a(<-),Database{@0x47f6473, name='loustooth'} => URLEndpoint{url=ws://localhost:4984/test}}: status changed: (0, 0) @C4ReplicatorStatus{level=0,completed=0,total=0,#docs=0,domain=0,code=0,info=0}
    I/CouchbaseLite/REPLICATOR:Replicator{@0x3e6fa38a(<-),Database{@0x47f6473, name='loustooth'} => URLEndpoint{url=ws://localhost:4984/test}} is STOPPED, progress 0/0, error: null

Status{activityLevel=STOPPED, progress=Progress{completed=0, total=0}, error=null}

… shows a one-shot replicator completing successfully (WebSocket protocol 1000), and then stopping.

From the previous parts of the log, it looks to me as if the SGW is saying that there are no documents in need of synchronization. Either it is already in the local DB, or there is some configuration issue that makes that doc ineligible for syncronization.