obscure-com / ti_touchdb

Titanium wrapper around Couchbase Mobile
102 stars 34 forks source link

Android: Replication 'ChangeTracker' errors when replicate.continuous = true #77

Open Galaloo opened 10 years ago

Galaloo commented 10 years ago

Running into some errors with replication.

    var manager = require('com.obscure.titouchdb').databaseManager, db = manager.getDatabase('testdb');

    var pullReplicate = db.createPullReplication('https://aaatest:aaatest@prepandpantry.iriscouch.com/aaatest');

    pullReplicate.continuous = true;

    pullReplicate.addEventListener('status', function(e) {
        Ti.API.info('syncing Changes ' + pullReplicate.completedChangesCount);
    });

    pullReplicate.start();

Gives me the following errors after a minute or two

[ERROR] :  ChangeTracker: com.couchbase.lite.replicator.ChangeTracker@52b45bac: Exception in change tracker
[ERROR] :  ChangeTracker: java.net.SocketTimeoutException: Read timed out
[ERROR] :  ChangeTracker:   at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_read(Native Method)
[ERROR] :  ChangeTracker:   at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:673)
[ERROR] :  ChangeTracker:   at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
[ERROR] :  ChangeTracker:   at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:191)
[ERROR] :  ChangeTracker:   at org.apache.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:220)
[ERROR] :  ChangeTracker:   at org.apache.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:183)
[ERROR] :  ChangeTracker:   at org.apache.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:155)
[ERROR] :  ChangeTracker:   at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:159)
[ERROR] :  ChangeTracker:   at org.codehaus.jackson.impl.Utf8StreamParser.loadMore(Utf8StreamParser.java:172)
[ERROR] :  ChangeTracker:   at org.codehaus.jackson.impl.Utf8StreamParser._skipWSOrEnd(Utf8StreamParser.java:2304)
[ERROR] :  ChangeTracker:   at org.codehaus.jackson.impl.Utf8StreamParser.nextToken(Utf8StreamParser.java:438)
[ERROR] :  ChangeTracker:   at org.codehaus.jackson.map.deser.std.UntypedObjectDeserializer.mapArray(UntypedObjectDeserializer.java:157)
[ERROR] :  ChangeTracker:   at org.codehaus.jackson.map.deser.std.UntypedObjectDeserializer.deserialize(UntypedObjectDeserializer.java:51)
[ERROR] :  ChangeTracker:   at org.codehaus.jackson.map.deser.std.MapDeserializer._readAndBind(MapDeserializer.java:319)
[ERROR] :  ChangeTracker:   at org.codehaus.jackson.map.deser.std.MapDeserializer.deserialize(MapDeserializer.java:249)
[ERROR] :  ChangeTracker:   at org.codehaus.jackson.map.deser.std.MapDeserializer.deserialize(MapDeserializer.java:33)
[ERROR] :  ChangeTracker:   at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2723)
[ERROR] :  ChangeTracker:   at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1900)
[ERROR] :  ChangeTracker:   at com.couchbase.lite.replicator.ChangeTracker.run(ChangeTracker.java:319)
[ERROR] :  ChangeTracker:   at java.lang.Thread.run(Thread.java:841)

The error messages will appear every few minutes.

Removing authentication with

    var pullReplicate = db.createPullReplication('https://prepandpantry.iriscouch.com/aaatest1');

Still throws the 'ChangeTracker' error. In both instances replication of changes still work.

Setting continuous to FALSE then no more error.

    pullReplicate.continuous = true;
FrancoisMeriaux commented 10 years ago

This is an issue we are also facing on Android with a continuous replication over HTTPS. From what we understand, the connection is closed after it has been idle for some time. However, on Android, the replication starts again after this error, then the error appears, then it starts again...

On iOS, we face a similar issue but the connection is killed silently, i.e. we do not get any error message and the replication does not recover from the error since it is not even detected.

The workaround we use so far is to automatically restart the replication after it has been idle for 50 seconds so we avoid the connexion being closed unintentionally.

For a proper fix, it seems that working on the heartbeat parameter can be an interesting lead, as discussed here https://groups.google.com/forum/#!topic/mobile-couchbase/edjN7wRNLM0

pegli commented 10 years ago

This appears to be an open issue with couchbase-lite-android: couchbase/couchbase-lite-android#330

I've subscribed to that issue and will update the module when the underlying library is fixed. A temporary workaround might be to use one-shot replication (continuous=false) and trigger it periodically via a timer.

riksof-raheel commented 9 years ago

hello i also faced that problem is that issue fixed now ?