CB Lite 2.0 -- Replication Error 400 Bad Request

Hi,

I’m new to Couchbase so this may be a stupid rookie mistake on my part. But I cannot get replication via the sync-gateway to work.

Some Basic Info:

  1. We are using Xamarin with .NET Standard Library (1.4).
  2. We are mainly building for a UWP project, but I checked Android and get the same error there.
  3. We are using CB-Lite 2.0 db016 // CB-Server 5.0.0 // Sync-Gateway 1.5

Code in the “MainPage.xaml.cs” of the .NET Standard Library (read: new-fancy-PCL):

public MainPage()
{
    this.db = new Database("sync-db");

    Uri url = new Uri("ws://our.couchbase.server.ip:4984/simon-sync-db");
    var config = new ReplicatorConfiguration(db, url);
    config.Continuous = true;
    config.ReplicatorType = ReplicatorType.PushAndPull;
    config.Authenticator = new BasicAuthenticator("testuser", "foo");
    config.Options.Channels = new List<String>();
    config.Options.Channels.Add("testchannel");
    
    this.replication = new Replicator(config);
    this.replication.StatusChanged += this.onReplicationCompleted;
    this.replication.Start();

    InitializeComponent();
}

void onReplicationCompleted(object sender, ReplicationStatusChangedEventArgs replicationEvent)
{
    if (replicationEvent.Status.Activity == ReplicatorActivityLevel.Stopped)
    {
        Console.WriteLine("Replication has completed.");
    }
}

Sync Gateway Config:

{
  "interface": ":4984",
  "adminInterface": ":4985",
  "databases": {
    "simon-sync-db": {
      "log": ["*"],
      "logFilePath": "/home/sync_gateway/log",
      "server": "http://localhost:8091",
      "bucket": "SIMON",
      "enable_shared_bucket_access": true,
      "enable_extended_attributes": true,
      "import_docs": "continuous",
      "username": "sync-gateway-user",
      "password": "******",
      "sync": `function(doc) {channel("testchannel");}`,
      "users": {
        "GUEST": {"disabled": false, "admin_channels": ["*"]},
        "testuser": {"password": "foo", "admin_channels": ["*"]}
      },
      "unsupported": {
        "replicator_2": true
      }
    }
  }
}

The Problem:
Well the most obvious problem is that the sync is not working. When creating a new document via .NET, it is not pushed into the bucket. Also I put a document into the bucket via admin-console and it is not pulled (db.GetDocument returns null).
When I break in “onReplicationCompleted” the “replicationEvent” also contains a LastError:
LastError = {LiteCore.LiteCoreException: LiteCoreException (400): Bad Request}

Also the console in which the sync-gateway runs doesn’t even show a connection-request. When I connect via browser (http://our.couchbase.server.ip:4985/simon-sync-db/_all_docs?include_docs=true) it shows the existing document correctly and in the console of the running sync-gateway I see the connection-request.

What I’ve tried

  • Using “walrus:” with a different bucket instead of the existing bucket on the cb-server
  • With and without Channel (see code above)
  • With and without User (see code above)

Can someone help? :frowning:

Thanks & Beste regards,
Lars

    Uri url = new Uri("ws://our.couchbase.server.ip:4984/simon-sync-db");

That should be an http: or https: URL.

Hi,

thanks for taking the time to check this out and answer! :slight_smile:

Yeah, I already tried that. But that throws an
LastError = {LiteCore.LiteCoreException: LiteCoreException (15): Unsupported replication URL scheme}

as it should per the documentation:
https://developer.couchbase.com/documentation/mobile/2.0/guides/couchbase-lite/native-api/replication/index.html?language=csharp
and
http://docs.couchbase.com/tutorials/travel-sample-mobile.html?lesson=03-architecture

because the new 2.0 replication protocol only supports websocket/blip.

I also tried blip:// with the same result as ws://. blips / wss don’t work because of certificate errors. But I would assume it should work without encryption. (?)

It appears we get the same error. We have been trying to get sync online between Server 5.0.0(3217)+Gateway 1.5v477 and WinForms .NET 4.7 and .NET Standard 2.0. Running the replicator from CBL NuGet 2.0db016 from desktop using Replication protocol 2.0 and ws:// URI gives us a 400 error and nothing showing in the gateway console, the websocket just disconnects uncleanly. When we try to connect to the ws:// using plugin in Chrome it does connect and shows up on the server that a connection occurred. We also tried to connect with and without authentication.

Debug log output from CBL and program, and C# test code attached.

repl_logandcode.zip (3.3 KB)

1 Like

Without reading the logs (on my phone) it almost seems like sync gateway is not configured for the version 2 replicator. In the unsupported section I think there needs to be an entry called “replicator_2” whose value is true.

Like the Gateway config Lars.s posted, we have that configured on our server.

“unsupported”: {
“replicator_2”: true
}

Hi borrden,

thanks for taking the time to answer!
I posted our sync-config above and it contains the unsupported replicator_2. It is placed inside the database-object as per documentation. I assume this is correct?

I would also assume avia_bdg also has this inside his sync-config.

Quick Update:

could this be a Bug in the .NET implementation?

We have successfully added the travel-sample bucket and setup the iOS 2.0 Demo (http://docs.couchbase.com/tutorials/travel-sample-mobile.html?lesson=01-overview). Everything works and behaves as expected.

To make sure, I’ll try and “port” the important parts from the iOS Demo to .NET. But from what I see at first glance in the code, the replication is the same as what we already tried in .NET and posted above in the OP :(.

1 Like

Another Update on that:

Looking through the iOS-Demo implementation the only relevant part seems to be in
startPushAndPullReplicationForCurrentUser
which is basically the identical code to what I posted in the OP (just in swift, obviously).

Adapting the above code to use the travel-sample database, correct user and channel (channel.{username}) – just like in the iOS demo – still results in the same behaviour with a 400 Bad Request error and nothing showing up in the sync-gateway-console.

Either I’m missing something very elementary or this is a bug in the .NET implementation.
I’ll open an issue on github. But if anyone has an idea or comment, please also post here :/.

1 Like

That’s certainly disappointing. The actual logic that creates those messages is in the native library so it must be web sockets acting up. I haven’t seen that issue (or at least I don’t remember seeing it) so I will fire up the tests for sync gateway again and see what happens tomorrow. I’ll report further on the ticket.

1 Like

Thanks a ton, borrrden!

For anyone interested, I opened the Github-Issue here:

I also in the meantime tried using Xamarin Shared Project and PCL, but both didn’t work either. I’m still not 100% certain, if it’s a bug or my own stupidity :/.

@borrrden : I saw on github, you made some efforts to port the todo-example into 2.0 UWP and .NET Standard. Is there any Version of that, that should currently work? (like the feature/2.0 branch?)

1 Like