Android _replicate REST Endpoint never receives docs from CouchDB

when attempting to perform a single replication from CouchDB to cbl the following occurs. The same code functions normally in iOS

using:
couch base-lite 1.1.0
cordova-android 4.1.1

  • the _replicate request is made to and from the remote db
  • both _replicate requests will stall for 30 seconds before returning a 200 response containing the sessionId but not the “ok” key as mentioned in the _replicate API doc. iOS does include the “ok” key and returns true.
  • the local doc count never increases.

This is how I am constructing the _replicate requests

`replicateFrom(bodyRequest?:cbl.IPostReplicateParams, otherDB?:string) {
    return new Promise((resolve, reject)=> {
        if (!otherDB && !this.syncUrl) reject(new Error('no sync url available to replicate from: ' + this.dbName));
        bodyRequest = {source: this.dbName, target: otherDB ? otherDB : this.syncUrl, continuous: false};
        var uri = new URI(this.localServerUrl).segment('_replicate');
        return this.processRequest('POST', uri.toString(), bodyRequest, null,
            (err, response)=> {
                if (err) reject(this.buildError('Error From replicate from Request', err));
                else resolve(response);
            });
    });
}

replicateTo(bodyRequest?:cbl.IPostReplicateParams, otherDB?:string) {
    return new Promise((resolve, reject)=> {
        if (!otherDB && !this.syncUrl) reject(new Error('no sync url available to replicate to: ' + this.dbName));
        bodyRequest = {source: otherDB ? otherDB : this.syncUrl, target: this.dbName, continuous: false};
        var uri = new URI(this.localServerUrl).segment('_replicate');
        this.processRequest('POST', uri.toString(), bodyRequest, null,
            (err, response)=> {
                if (err) reject(this.buildError('Error From replicate to Request', err));
                else resolve(response);
            });
    });
}

 processRequest(verb:string, url:string, data:Object, headers:Object, cb:Function, isAttach?:boolean):void {
    var http = new XMLHttpRequest();
    http.open(verb, url, true);
    if (headers) _.forOwn(headers, (value:any, key)=> { http.setRequestHeader(key, value); });
    if (isAttach)http.responseType = 'blob'; //options "arraybuffer", "blob", "document", "json", and "text"

    //state change callback
    http.onreadystatechange = () => {
        if (http.readyState == 4 && http.status >= 200 && http.status <= 299) {
            if (isAttach) cb(false, http.response);
            else cb(false, JSON.parse(http.responseText));
        }
        else if (http.readyState == 4 && http.status >= 300) cb({status: http.status, response: http.responseText});
    };

    //send request variations
    if (verb === 'PUT' && isAttach) http.send(data);
    else if (verb === 'GET' || verb === 'DELETE')http.send();
    else if (verb === 'POST' || verb === 'PUT' && !_.isNull(data))http.send(JSON.stringify(data));
    else http.send();
}

I have posted this as github issue #708 in the couchbase-lite-android repo

Hi @jfspencer,

I haven’t noticed this.
Can you share a sample project so we can reproduce the issue and noticeable delay in getting a response from the database?

James

Ok just noticed you provided the source repo in the github issue. Very cool project!! Do you have a sample project handy that uses this plugin?

James

Ah yes. I forgot to link it. https://github.com/happieio/typeapp I just updated it to link to cordova-android@5.0.0 to support marshmallow. I have been doing these tests on marshmallow, nexus 5x. I am getting the same results in this test app. I sent an email to the one listed on your github account with the sync gateway url .

you can replace the sync gateway url in the app here https://github.com/happieio/typeapp/blob/master/src/lib/data/db/api.ts#L64-L65

the initial view has a two way replication button toward the bottom.

Side note the typeapp repo is a submodule within the couchbase-lite adapter repo.

To close this topic, the issue was related to our Couchbase Server implementation. After migrating to new infrastructure the issue resolved itself.