I have a Couchbase bucket which cause the following strange behaviour for iOS CBL framework.
When you launch an application the very first time (database is not yet created) and start a pull-process it works as expected: puller “listen” to SyncGateway and synchronises changes as soon as they happen in the database (Python script changes it via SyncGateway API).
However if the app is terminated (or sent to background) and then go active again the puller thread never starts again and synchronisation is not working anymore.
After some checks I figured out that the problem is in the bucket. Because I run the same code on other bucket and synchronization is working after any number of “go-background-go-active” cycles. Thus some data related to SyncGateway itself triggers this behaviour on iOS. Android framework works well on the “bad” bucket.
Could you give me a hint about the direction to dig for the issue? At the moment I have saved mobile app logs for both good and bad buckets: the initial launch, logs when the app goes background, logs when the app goes active. The initail logs are huge and seems to look similar. I didn’t manage to find any signes of “complains” which would indicate any problems during database creation. However the logs are very different when app goes background and go active again. This why I concluded that iOS framework fails to restart puller thread.
If necessary I can provide those logs, don’t see a reason to put them here as they are bulky. As well I have a dataset where the problem can be reproduced any number of times.
At the moment I found only one workaround to solve the problem: just recreated every document of the “bad” bucket in a new bucket. After that mobile works very well. However, it’s a sort of “brute force” solution and now I don’t know when this issue is going to happen again. It’s quite a problem because it affects all my iOS users.
So any help would be appreciated. Thank you very much for advance!
The code I have to start the puller:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self startLogs];
[self startSync];
return YES;
}
- (void)startSync {
NSString* url = @"http://127.0.0.1:4984/dbname/";
NSString* username = @"1709181@mail.com";
NSString* password = @"c3cdcb95c0f8debb3a7889e3de230cae32a95f21";
CBLManager *manager = [CBLManager sharedInstance];
NSError *error;
CBLDatabase* database = [manager databaseNamed:@"dbname" error:&error];
if (error) {
NSLog(@"error getting database %@", error);
}
CBLReplication *pull;
id<CBLAuthenticator> auth;
auth = [CBLAuthenticator basicAuthenticatorWithName:username password:password];
pull = [database createPullReplication: [NSURL URLWithString:url]];
pull.continuous = YES;
pull.authenticator = auth;
[pull start];
}
- (void)startLogs {
NSArray *groups = @[@"ArrayDiff",
@"BLIP",
@"BLIPLifecycle",
@"ChangeTracker",
@"Database",
@"JSONReader",
@"Listener",
@"Model",
@"MultiStreamWriter",
@"Query",
@"Reachability",
@"RemoteRequest",
@"Server",
@"SQL",
@"Sync",
@"SyncPerf",
@"Upgrade",
@"Validation",
@"View"];
for (NSString* g in groups) {
[CBLManager enableLogging:g];
}
}