Can't connect Couchbase Lite app to walrus


#1

Hi,

I’m new to Couchbase and I’ve gone through tutorials to try to learn how to use Couchbase Lite with Sync Gateway and Couchbase Server. My CRUD operations are working fine and I’m able to create a document and store it in the local Couchbase Lite database, but I am unable to push a document to the walrus server let alone Couchbase Server.

I’m running Couchbase Lite from Xamarin for Visual Studio on Windows and I have the latest Couchbase Lite 1.3.0. update.

Here’s my C# code - I’m calling StartReplications from the OnCreate method:

Uri syncGatewayURI = new Uri(“http://127.0.0.1:4984/db”);

    void StartReplications()
    {
        Replication pull = db.CreatePullReplication(syncGatewayURI);
        Replication push = db.CreatePushReplication(syncGatewayURI);
        pull.Continuous = true;
        push.Continuous = true;
        pull.Start();
        push.Start();
    }

Here’s my serviceconfig.json file:

{
“log”: [“CRUD+”, “REST+”, “Changes+”, “Attach+”],
“adminInterface”: “127.0.0.1:4985”,
“interface”: “0.0.0.0:4984”,
“databases”: {
“db”: {
“server”: “walrus:data”,
“sync”:
function(doc){
channel(doc.channels);
},
“users”: {
“GUEST”: {“disabled”: true, “admin_channels”: ["*"]}
}
}
}
}

Here’s the section of my logs that shows the errors:

Thread started: #7
08-13 22:18:30.664 D/Mono (19876): [0xb89144e8] worker starting
[0:] INFO) SYNC (Replication): [9] 2016-8-13 10:18:30.664-05:00 Attempting to start puller (5016c5c3-5932-43e1-94b8-e045e4db6b03)
[0:] INFO) SYNC (Replication): [9] 2016-8-13 10:18:30.670-05:00 Attempting to start pusher (d264b8ac-a1f9-4521-8b28-b9a8ecec32e8)
[0:] INFO) SYNC (NetworkReachabilityManager): [9] 2016-8-13 10:18:30.766-05:00 Didn’t get successful connection to http://127.0.0.1:4984/db
[0:] INFO) SYNC (Replication): [9] 2016-8-13 10:18:30.779-05:00 Remote endpoint is not reachable, going offline…
[0:] INFO) SYNC (Replication): [9] 2016-8-13 10:18:30.785-05:00 Error set during replication (application may continue):
System.Net.WebException: Error: ConnectFailure (Connection refused) —> System.Net.Sockets.SocketException: Connection refused
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x000cb] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net.Sockets/Socket.cs:1313
at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x0019b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net/WebConnection.cs:195
— End of inner exception stack trace —
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x0005e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1005
at System.Net.HttpWebRequest.GetResponse () [0x0000e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1019
at Couchbase.Lite.NetworkReachabilityManager.CanReach (System.String remoteUri, TimeSpan timeout) [0x00000] in /Users/jenkins/jenkins/workspace/couchbase-lite-net-build@2/1.3.0/Android/couchbase-lite-net/src/Couchbase.Lite.Shared/Util/ArraySegment.cs:194
[0:] INFO) SYNC (Replication): [9] 2016-8-13 10:18:30.830-05:00 NotifyChangeListeners (0/0, state=Running (batch=0, net=0))
[0:] INFO) SYNC (Replication): [9] 2016-8-13 10:18:30.873-05:00 Beginning replication process…
[0:] INFO) SYNC (NetworkReachabilityManager): [9] 2016-8-13 10:18:30.876-05:00 Didn’t get successful connection to http://127.0.0.1:4984/db
[0:] INFO) SYNC (Replication): [9] 2016-8-13 10:18:30.882-05:00 Remote endpoint is not reachable, going offline…
[0:] INFO) SYNC (Replication): [9] 2016-8-13 10:18:30.886-05:00 Error set during replication (application may continue):
System.Net.WebException: Error: ConnectFailure (Connection refused) —> System.Net.Sockets.SocketException: Connection refused
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x000cb] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net.Sockets/Socket.cs:1313
at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x0019b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net/WebConnection.cs:195
— End of inner exception stack trace —
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x0005e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1005
at System.Net.HttpWebRequest.GetResponse () [0x0000e] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1019
at Couchbase.Lite.NetworkReachabilityManager.CanReach (System.String remoteUri, TimeSpan timeout) [0x00000] in /Users/jenkins/jenkins/workspace/couchbase-lite-net-build@2/1.3.0/Android/couchbase-lite-net/src/Couchbase.Lite.Shared/Util/ArraySegment.cs:194
[0:] INFO) SYNC (Replication): [9] 2016-8-13 10:18:30.897-05:00 NotifyChangeListeners (0/0, state=Running (batch=0, net=0))
[0:] INFO) SYNC (Replication): [9] 2016-8-13 10:18:31.165-05:00 Beginning replication process…

Later on in my logs I found something related to a System.AggregateException:

[0:] WARN) SYNC (RemoteSession): [6] 2016-8-13 10:18:38.193-05:00 Http Message failed to send, or got error response, passing to callback… http://127.0.0.1:4984/db/_local/d42e4cc12c98f5546f34c0a4dd9fa7f07a56374c, :
System.AggregateException: One or more errors occurred. —> System.AggregateException: One or more errors occurred. —> System.AggregateException: One or more errors occurred. —> System.Net.WebException: Error: ConnectFailure (Connection refused) —> System.Net.Sockets.SocketException: Connection refused
at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x000cb] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net.Sockets/Socket.cs:1313
at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x0019b] in /Users/builder/data/lanes/3540/1cf254db/source/mono/mcs/class/System/System.Net/WebConnection.cs:195
— End of inner exception stack trace —

I’ve looked around and took other steps to ensure nothing else besides my connection was wrong. I’ve checked out the topic here:
https://forums.couchbase.com/t/persistent-data-with-walrus/8790
and made sure that the data directory exists where I am running sync_gateway and that my user account has write access to the directory. It didn’t exist for me, so I added in the directory:

My Sync Gateway is also running properly and I’m able to view the admin port:

Going to http://127.0.0.1:4984/db/ in the browser gives me this:

How do I resolve this connection issue?


#2

Local host on android is not your computer, it is your emulator or device. Search for “connect to local host from android emulator”. It will be something like 10.0.2.0 but I can’t remember the exact IP address.


#3

I’m testing using a physical android device (Android 5.1 - API 22) so I didn’t use that IP. But I tried using the 10.0.2.2. IP address just in case and I still got these errors:

I also tried my computer’s IP address instead of the loaclhost ones but that didn’t work either.


#4

it should be your computer address. Try changing 0.0.0.0:4984 to just :4984 and verify that you can reach the IP address from the android browser.


#5

Alright thanks, I found the right IP address. It turned that I had to use my 192.168.x.x. internal IP instead of the external one.

But now I’m getting an error related to authentication:

08-15 12:09:15.870 I/mono-stdout(15870): 8/15/2016 12:09:15 PM|Fatal|WebSocket.connect|WebSocketSharp.WebSocketException: Requires the authentication.
8/15/2016 12:09:15 PM|Fatal|WebSocket.connect|WebSocketSharp.WebSocketException: Requires the authentication.

The log also had a line that said [Status Code = Unauthorized]

And this log entry said something about an inaccessible method:

[0:] INFO) CHANGE TRACKER (SocketChangeTracker): [5] 2016-8-15 12:09:16.226-05:00 SocketChangeTracker[db] got an exception, stopping NOW…:
System.AggregateException: One or more errors occurred. —> System.AggregateException: One or more errors occurred. —> System.AggregateException: One or more errors occurred. —> System.MethodAccessException: Method System.Net.WebHeaderCollection:AddValue (string,string)' is inaccessible from methodSystem.Net.Http.HttpClientHandler/c__async0:MoveNext ()’