Replication does not continue when back online

Couchbase Lite Version: 1.4
Platform: iOS

What’s happening
We’re using Couchbase Lite 1.4 (iOS). We noticed that when the internet is gone, replication status turns to “Offline” which is expected. The user can still create documents offline as expected too.

The Problem
However, when internet is back, sync does not resume. Documents created locally does not get pushed to the server. Both replication objects (push and pull) still have the “Offline” status but both are “running”. Only when I stop the the replication and start it does sync resume. We use continuous replication for both the pull and push replicators.

Logged Pull and Push Replicator Statuses and Last Error.

11:21:00.751| Sync: CBLReplication[from http://xxx.xxx.xxx:4984/xxx]: idle, progress = 0 / 0, err: (null)
Replication Changed::::
PULL Status:: Optional(2)
PUSH Status:: Optional(2)
Is PULL Running? Optional(true)
Is PUSH Running? Optional(true)
PULL last error:: nil
PUSH last error:: nil

Turned Off Wifi

11:30:19.844‖ Sync: CBLRestPuller[http://xxx.xxx.xxx:4984/xxx]: Reachability state = <xxx.xxx.xxx>:unreachable (00), suspended=0
11:30:19.844‖ Sync: CBLRestPuller[http://xxx.xxx.xxx:4984/xxx]: Going offline
11:30:19.844‖ Sync: CBLRestPuller[http://xxx.xxx.xxx:4984/xxx]: postProgressChanged (0/0, active=0 (batch=0, net=0), lastSeq=61955, online=0, error=(null))
11:30:19.853‖ Sync: CBLRestPuller[http://xxx.xxx.xxx:4984/xxx]: ChangeTracker stopped; error=(null)
11:30:19.854| Sync: CBLReplication[from http://xxx.xxx.xxx:4984/xxx]: offline, progress = 0 / 0, err: (null)
Replication Changed::::
PULL Status:: Optional(1)
PUSH Status:: Optional(2)
Is PULL Running? Optional(true)
Is PUSH Running? Optional(true)
PULL last error:: nil
PUSH last error:: nil
11:30:19.865‖ Sync: CBLRestPusher[http://xxx.xxx.xxx:4984/xxx]: Reachability state = <xxx.xxx.xxx>:unreachable (00), suspended=0
11:30:19.865‖ Sync: CBLRestPusher[http://xxx.xxx.xxx:4984/xxx]: Going offline
11:30:19.865‖ Sync: CBLRestPusher[http://xxx.xxx.xxx:4984/xxx]: postProgressChanged (0/0, active=0 (batch=0, net=0), lastSeq=6667, online=0, error=(null))
11:30:19.865| Sync: CBLReplication[to http://xxx.xxx.xxx:4984/xxx]: offline, progress = 0 / 0, err: (null)
Replication Changed::::
PULL Status:: Optional(1)
PUSH Status:: Optional(1)
Is PULL Running? Optional(true)
Is PUSH Running? Optional(true)
PULL last error:: nil
PUSH last error:: nil

When I turn the Wifi back on again, all the documents I made locally are not being pushed. I’m also not receiving new changes from the server. More than 30 minutes have passed but still no change in status. Only when I stop sync and starting will I be able to pull and push changes.

Do you see any logs after turning wifi back on that deal with “Reachability” ?

I would suggest filling a bug report on the GitHub repo if you have a project that can reliably reproduce this. A word of warning though: 1.4 is just 2 months away from its end-of-life date so community submitted bug reports will probably not be prioritized very high.

If this is a new project I’d recommend using the latest version in the 2.x line.

There aren’t any logs at all when I turned the Wifi back on.

There is this log though when I turn it off:

2019-01-30 13:15:27.223372+0800 APP DEV[2251:191337] [] nw_socket_output_finished shutdown(9, SHUT_WR) [49: Can't assign requested address]
2019-01-30 13:15:30.618241+0800 APP DEV[2251:191567] [] nw_socket_output_finished shutdown(15, SHUT_WR) [49: Can't assign requested address]
2019-01-30 13:15:33.309902+0800 APP DEV[2251:191557] [] nw_socket_output_finished shutdown(16, SHUT_WR) [49: Can't assign requested address]

Aw, this isn’t a new project. But when we started this, I was already eyeing Couchbase 2 that time but it was still a developer build.

By any chance, does Sync Gateway settings/configuration have any effect or may have contributed to the problem? If it helps, we create the replicators with this method in mobile:

- (void) setCookieNamed: (NSString*)name
              withValue: (NSString*)value
                   path: (nullable NSString*)path
         expirationDate: (nullable NSDate*)expirationDate
                 secure: (BOOL)secure;

That method doesn’t look like it creates a replicator, but rather creates a cookie on the replicator.

There are no Sync Gateway settings that affect the offline handling of Couchbase Lite. In general it should simply work. @jens or @pasin might know something specific to iOS…

Ah sorry, you’re right. This is the whole code:

    let pullReplication = database.createPullReplication(settings.syncUrl)
    pullReplication.continuous = settings.continuous
    pullReplication.channels = settings.channels
        
    pullReplication.setCookieNamed(session.name,
                                       withValue: session.id,
                                       path: "/\(settings.bucketName)",
        expirationDate: session.expiration,
        secure: settings.secure)

Same code for push replication without setting the channels part.

Gotta ask though, we’re using Couchbase enterprise. Won’t the bugfix be prioritized though?

If you are using Couchbase Enterprise then your first point of contact for your issue should be the support team. They are there to help.

Ohhhh, noted on this. I’m not sure if there is such a thing as Couchbase Lite Enterprise but our server side stuff is Enterprise. Sorry, I’m not really sure about web/server stuff.

But if that’s the case, we have support for Couchbase Lite?

Couchbase Lite Enterprise is separate from Couchbase Server. I am not aware of the exact details, for that you will need to talk to the sales team.

Oh, there really is a Couchbase Lite Enterprise. We just installed ours through Cocoapods. There wasn’t any setup for us to start using Couchbase Lite except to set the exact endpoints so it can Sync the data.

There’s no secret key or anything.

If you have an Enterprise license for Sync Gateway, then you have Couchbase Lite support too.

In the logs there should be a message like Reachability state =... after going back online. If there isn’t, that means that the OS isn’t notifying us about a network-reachability change.

What exactly do you do to take the connection offline / online?
Are you going through a client HTTP proxy to get to Sync Gateway?