BLIP+WebSocket connection error: read tcp X.X.X.X:4984->X.X.X.X:22513: read: connection reset by peer

i’m starting using sync gateway in a staging test, with at most 10-15 android app connected.
I’m using couchbase lite 2.0, couchbase community 5.1.1 and sync gateway 2, in an ubuntu 18.04 environment with 16GB ram and dual core Intel® Xeon®.
When i start the main activity, as docs, i open a continuous replication:

private void setReplicator () {
        try {
            URI uri = new URI(REPLICATION_URL);

            Endpoint endpoint = new URLEndpoint(uri);
            ReplicatorConfiguration replConfig = new ReplicatorConfiguration(MyDatabase.getInstance().getDatabase(), endpoint);

            List<String> channels = Channels.getChannels();

            String user =  BuildConfig.COUCHBASE_USERNAME;
            String password = BuildConfig.COUCHBASE_PASSWORD;

            Authenticator auth = new BasicAuthenticator(user, password);
            mReplicator = new Replicator(replConfig);
            mReplicator.addChangeListener(new ReplicatorChangeListener() {
                public void changed(ReplicatorChange change) {
                    mReplicatorStatus = change.getReplicator().getStatus().getActivityLevel();
                    Log.d("REPLICATORSTATUS", mReplicatorStatus.toString());
        } catch (URISyntaxException e) {

In development stage i didn’t have any issue, but now having multiple app connected i’m start noticing in sync_gatewa_logs.json those messages:

--> BLIP+WebSocket connection error: read tcp X.X.X.X:4984->X.X.X.X:17634: read: connection reset by peer
--> BLIP+WebSocket connection error: read tcp X.X.X.X:4984->X.X.X.X:17621: read: connection reset by peer
--> BLIP+WebSocket connection error: read tcp X.X.X.X:4984->X.X.X.X:25376: read: connection timed out
--> BLIP+WebSocket connection error: read tcp X.X.X.X:4984->X.X.X.X:54763: read: connection timed out

and normally after those the app keeps going to load indefinitely, reaching sometimes the STOPPED status.
Do you know why? How should i handle multiple connection?

Thank you in advance.

That looks like Sync Gateway thinks that the client (Couchbase Lite) is closing it’s end of the websocket.

Are there any Couchbase Lite logs? You might need to enable more verbose logging on Couchbase Lite.

These are TCP-level errors.

“Connection reset by peer” means that the client terminated the TCP connection without going through the normal close procedure. Generally this means that the process exited abruptly, i.e. the app crashed.

“Connection timed out” means that the client isn’t sending back TCP acknowledgement packets. Generally this means that connectivity was lost somewhere between client and server – the client may have lost its network connection, or a router along the path went down.

So it means that is in the client the error? Because if I check the sync_gateway_error.log the number of times that this problem happens is increasing without touching the application, therefore I though it was a SW problem. Do you suggested something to check why it 's happening?

Thank you

Why don’t you look at what’s going on with the client? If it’s crashing, there should be crash reports/logs.

The client only shows an endless loading view. When the app opens, a loading view is showed until the replicator is in IDLE state, and in those cases that state is never reach.
Do you think the sync_gateway.json could be the cause?

  "CORS": {
     "Headers": ["Content-Type"]
  "adminInterface": ":4985",
  "databases": {
    "omnitrace_cluster": {
      "bucket": "omnitrace",
      "password": "password",
      "username": "username",
      "import_docs": "continuous",
      "enable_shared_bucket_access": true,
      "users": {
        "GUEST": {"disabled": false, "admin_channels": ["*"]}
      "sync": `function (doc, oldDoc) {

Also, I noticed this logs once in a while:

changes_view: Query took 291.60512ms to return 7 rows, options = db.Body{"startkey":[]interface {}{"6e3d7915-2f57-4abb-917f-60e4325a6e1f", 0x1}, "endkey":[]interface {}{"6e3d7915-2f57-4abb-917f-60e4325a6e1f", 0xd}, "stale":false}

Again, if it’s the client that’s showing problems, focus on the client. What is it logging?