Replicator pull continous stop after network error in couchbase lite 2.8.x android

Hi,

Replicator PULL continous stop after network error in couchbase lite 2.8.x android.
Today, I tested 2.8.5 and 2.8.4.

Steps :
1 / launch app
2 / wait IDLE state replicator
3 / turn off network

Logs:

2021-04-07 11:57:48.300 2414-2477/com.mapotempo.testcouchbase E/CouchbaseLite/NETWORK: {N8litecore4repl12C4SocketImplE#1} WebSocket closed abnormally (reason=Unknown error 10)
2021-04-07 11:57:48.302 2414-2454/com.mapotempo.testcouchbase E/CouchbaseLite/REPLICATOR: {Repl#2} Got LiteCore error: LiteCore error 26 "unexpected exception"
2021-04-07 11:57:48.309 2414-2414/com.mapotempo.testcouchbase I/Replicator: Error code ::  26
2021-04-07 11:57:48.309 2414-2414/com.mapotempo.testcouchbase I/Replicator: Status ::  STOPPED

Code :

public class MainActivity extends AppCompatActivity
{
    private static final String TAG = "Replicator";
    private Database mDatabase;
    private Replicator mReplicator;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        CouchbaseLite.init(getApplicationContext());

        DatabaseConfiguration config = new DatabaseConfiguration();

        config.setDirectory(getApplicationContext().getFilesDir().getAbsolutePath());

        try
        {
            mDatabase = new Database("test", config);

            Endpoint targetEndpoint = new URLEndpoint(new URI("URL"));
            ReplicatorConfiguration replConfig = new ReplicatorConfiguration(mDatabase, targetEndpoint);
            replConfig.setReplicatorType(ReplicatorConfiguration.ReplicatorType.PULL);
            replConfig.setContinuous(true);
            replConfig.setAuthenticator(
                new BasicAuthenticator("LOGIN", "PASSWORD".toCharArray()
                )
            );
            mReplicator = new Replicator(replConfig);

            mReplicator.addChangeListener(change -> {
                if (change.getStatus().getError() != null) {
                    Log.i(TAG, "Error code ::  " + change.getStatus().getError().getCode());
                }
                Log.i(TAG, "Status ::  " + change.getStatus().getActivityLevel().toString());
            });

            mReplicator.start();

        } catch (CouchbaseLiteException | URISyntaxException exception)
        {
            exception.printStackTrace();
            finish();
        }
    }

    @Override
    protected void onDestroy()
    {
        try
        {
            if (mDatabase != null) {
                mDatabase.close();
            }
        } catch (CouchbaseLiteException exception)
        {
            exception.printStackTrace();
        }
        super.onDestroy();
    }
}

Tested on Java; Android 10; SM-A202F
Best regards

2 Likes

in couchbase lite 2.7.1, it works, we have OFFLINE state

2021-04-07 12:30:44.964 14926-14926/com.mapotempo.testcouchbase I/REPLICATOR: Status ::  CONNECTING
2021-04-07 12:30:45.522 14926-14926/com.mapotempo.testcouchbase I/REPLICATOR: Status ::  BUSY
2021-04-07 12:30:45.650 14926-14926/com.mapotempo.testcouchbase I/REPLICATOR: Status ::  IDLE
2021-04-07 12:30:50.794 14926-14992/com.mapotempo.testcouchbase E/CouchbaseLite/REPLICATOR: {Repl#5} Got LiteCore error: WebSocket error 1001 "WebSocket connection closed by peer"
2021-04-07 12:30:50.818 14926-14926/com.mapotempo.testcouchbase I/REPLICATOR: Error code ::  11001
2021-04-07 12:30:50.818 14926-14926/com.mapotempo.testcouchbase I/REPLICATOR: Status ::  BUSY
2021-04-07 12:30:50.906 14926-14926/com.mapotempo.testcouchbase I/REPLICATOR: Error code ::  11001
2021-04-07 12:30:50.906 14926-14926/com.mapotempo.testcouchbase I/REPLICATOR: Status ::  OFFLINE

@Giallon Hmmm… interesting.

Can you give me a little bit more log? Those 4 lines are not enough to identify the location of the bug. Can you set the debug level to at least VERBOSE and provide logs for the whole connection process?

In particular, I need the log line (v2.8.5) that looks like this:
I/CouchbaseLite/NETWORK: WebSocket CLOSED …

… and I do believe that this is probably a bug.

FWIW, here is what I believe is happening:
When the remote is disconnected, OkHttp, the package we use for websocket communication, reports the error code that it gets from the OS. The OS uses POSIX codes which, perhaps surprisingly, are platform dependent! In the process of correcting how some failures are reported, I inadvertently made Android (where we can identify the POSIX code) report connection failure as an unknown failure type. Core, which manages the replicator, considers an unknown failure unrecoverable.

Thanks @blake.meike for your answer

With your instructions , here are the logs :

2021-04-07 19:38:56.469 12680-12680/com.mapotempo.testcouchbase I/CouchbaseLite/NETWORK: {N8litecore4blip10ConnectionE#3}==> N8litecore4blip10ConnectionE ->wss://mobile.fleet.beta.mapotempo.com:4984/db/_blipsync @0x76cb38b110
2021-04-07 19:38:56.469 12680-12680/com.mapotempo.testcouchbase I/CouchbaseLite/NETWORK: {N8litecore4blip10ConnectionE#3} Opening connection...
2021-04-07 19:38:56.473 12680-12836/com.mapotempo.testcouchbase I/CouchbaseLite/NETWORK: {N8litecore4repl12C4SocketImplE#6}==> N8litecore4repl12C4SocketImplE wss://mobile.fleet.beta.mapotempo.com:4984/db/_blipsync @0x7762b87430
2021-04-07 19:38:56.473 12680-12836/com.mapotempo.testcouchbase I/CouchbaseLite/NETWORK: {N8litecore4repl12C4SocketImplE#6} Connecting...
2021-04-07 19:38:57.716 12680-12882/com.mapotempo.testcouchbase I/CouchbaseLite/NETWORK: {N8litecore4repl12C4SocketImplE#6} Got HTTP response (status 101)
2021-04-07 19:38:57.718 12680-12882/com.mapotempo.testcouchbase I/CouchbaseLite/NETWORK: {N8litecore4repl12C4SocketImplE#6} Connected!
2021-04-07 19:38:57.718 12680-12882/com.mapotempo.testcouchbase I/CouchbaseLite/NETWORK: {N8litecore4blip10ConnectionE#3} Connected!
2021-04-07 19:38:57.718 12680-12882/com.mapotempo.testcouchbase I/CouchbaseLite/NETWORK: WebSocket CONNECTED!
2021-04-07 19:38:57.728 12680-12835/com.mapotempo.testcouchbase I/CouchbaseLite/NETWORK: {N8litecore4blip6BLIPIOE#7}==> N8litecore4blip6BLIPIOE ->wss://mobile.fleet.beta.mapotempo.com:4984/db/_blipsync @0x76cb4840c8
2021-04-07 19:39:09.281 12680-12882/com.mapotempo.testcouchbase I/CouchbaseLite/NETWORK: WebSocket CLOSED
    javax.net.ssl.SSLException: Read error: ssl=0x76d1ed8e48: I/O error during system call, Software caused connection abort
        at com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)
        at com.android.org.conscrypt.NativeSsl.read(NativeSsl.java:411)
        at com.android.org.conscrypt.ConscryptFileDescriptorSocket$SSLInputStream.read(ConscryptFileDescriptorSocket.java:583)
        at okio.Okio$2.read(Okio.java:140)
        at okio.AsyncTimeout$2.read(AsyncTimeout.java:237)
        at okio.RealBufferedSource.request(RealBufferedSource.java:72)
        at okio.RealBufferedSource.require(RealBufferedSource.java:65)
        at okio.RealBufferedSource.readByte(RealBufferedSource.java:78)
        at okhttp3.internal.ws.WebSocketReader.readHeader(WebSocketReader.java:117)
        at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.java:101)
        at okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.java:273)
        at okhttp3.internal.ws.RealWebSocket$1.onResponse(RealWebSocket.java:209)
        at okhttp3.RealCall$AsyncCall.execute(RealCall.java:174)
        at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
2021-04-07 19:39:09.282 12680-12882/com.mapotempo.testcouchbase I/CouchbaseLite/NETWORK: {N8litecore4repl12C4SocketImplE#6} sent 135 bytes, rcvd 121, in 11.563 sec (12/sec, 10/sec)
2021-04-07 19:39:09.283 12680-12829/com.mapotempo.testcouchbase I/CouchbaseLite/NETWORK: {N8litecore4blip10ConnectionE#3} Closed with Unknown error 10: unexpected exception

Best regards

Awesome, @Giallon . I’ve filed

https://issues.couchbase.com/browse/CBL-1841

to track the issue.

Thanks you @blake.meike