chages function sometimes is not triggered

75 views
Skip to first unread message

Pavel Vasilyev

unread,
Jun 16, 2016, 8:56:29 PM6/16/16
to PouchDB
Hi all,

I have CouchDB 1.5 on a server and an Android application that runs PouchDB in WebView to sync data from that CouchDB server.
In the Android application I create local copy of database. At first I do replicate.from() from that CouchDB. When replication is completed I run live sync between PouchDB and that CouchDB server.
Then in the Android application I do subscribe on changes in the local db instance by calling changes() function.

I run this app on 2 phones and on the one phone I add and remove documents by calling put() and remove() functions to the local db correspondingly.
On the second phone I observe notifications from PouchDB in events triggered by changes() function.

The issue is that I see sometimes that changes events may be stopped triggering on the second phone if I do add and remove operations a bit fast. So finally on the second I don't see the same amount of documents as on CouchDB server and on the first phone.

But! if I do put() or remove() on the second phone to the local db even if there is no connection to the CouchDB server, I got changes events with some amount of documents that were added/removed by the first phone. So it looks like the PouchDB stuck and only after I did some additional action under the local db, PouchDB woke up and continued returning documents.

Sometimes adding another new document on the first phone also may get back changes function working.

I used PouchDB 4.0.3 version, then tried 5.4.3, but see the same issue.

Here is some part of code:

    self.syncHandle = self.localDb.replicate.from(self.remoteDb, {
       
retry: true,
        back_off_function
: function (delay) {
            console
.warn('Backoff function called, delay: ' + delay);
   
           
return backoff_timeout + 500;
       
}
   
}).on('complete', function (result) {
        console
.log('Completed initial replication');
        console
.log(result);
   
        console
.log('Starting continious replication');
       
self.syncHandle = self.localDb.sync(self.remoteDb, {
           
retry: true,
            live
: true,
            timeout
: 10000,
            heartbeat
: 5000,
            back_off_function
: function (delay) {
                console
.warn('Backoff function called, delay: ' + delay);

               
return backoff_timeout + 500;
           
}
       
}).on('change', function(change) {
            console
.info('Got change while continiously replicating: ' + change);
       
}).on('denied', function(error) {
            console
.error('Denied replication');
            console
.error(error);
       
}).on('active', function() {
            console
.log('Activated replication');
       
}).on('paused', function(error) {
            console
.warn('Paused replication');
            console
.warn(error);
       
}).on('error', function(error) {
            console
.error('Failed to do replication');
            console
.error(error);
       
});
   
}).on('error', function(error) {
        console
.error('Failed to do initial replication');
        console
.error(error);
   
});

    var subscription = self.localDb.changes({
        since
: 'now',
        live
: true,
        include_docs
: true,
   
}).on('change', function(change) {
        callback
(change.doc);
   
}).on('complete', function(change) {
        console
.error('Changes feed somehow completed');
   
}).on('error', function(err) {
        console
.error('!!!! subscribe error !!!!');
        console
.error(err);
   
});




Nolan Lawson

unread,
Jun 17, 2016, 9:45:22 AM6/17/16
to PouchDB
Hi Pavel,

That's a really strange issue, and it sounds like a bug. Could you please file an issue at http://github.com/pouchdb/pouchdb/issues/ ?

Also if you could let us know which version of Android this is, and which PouchDB adapter you're using (or is it one of the SQLite Plugins?) that would be helpful.

- Nolan
Reply all
Reply to author
Forward
0 new messages