Embarrassingly dumb question - can't get sync going on .Net 6 or 7

I have an app that works on Xam.Mac and iOS, but SG and CBL are not supported there. Upgrading my mac to Ventura caused the Mac app to stop working. I could never get it going again (after several weeks of effort).

So I’m working on upgrading my app to .Net 6 or 7. First step was to create a test application - a simple default “Mac OS .Net App”. That runs fine. Then I added the CBL nuget package and libLiteCore native reference. Then the only code I added was to open a DB, check it works, and start a sync (I’ll paste the code below).

Open/Write/Read to the database works, but the sync fails with the following errors:

The type initializer for 'Couchbase.Lite.Support.MacProxy' threw an exception.
2023-1-26 10:09:39.521+13:00 [3]| ERROR)  [Network] {C4SocketImpl#15} No response received after 15 sec -- disconnecting
...
2023-1-26 10:09:39.524+13:00 [24]| ERROR)  [Replicator] {Repl#14} Got LiteCore error: Network error 3, "connection timed out"

I’ve turned the logging up on the sync server, and no connection comes in (i.e. no messages). I’ve tried a sync server running remotely and locally:

2023-1-26 10:09:39.525+13:00 [24]| INFO)  [Replicator] (Replicator) [24] Replicator[<*> ws://localhost:4984/testdb] is Connecting, progress 0/0

Same results either way. I’ve also tried this using .Net6 and .Net7 and over TLS.

I know the sync server does work because prior to the Ventura upgrade, everything was fine. Also, the iOS app on my phone still connects and syncs and works.

Does anyone have an idea as to how I can troubleshoot this? Or what might have gone wrong after the Ventura upgrade? Why is that simple program generating an exception in MacProxy (BTW - I think that MacProxy has some bad paths - see here)

Many thanks.
Paul.

Below is a copy of the code that was added to the ViewController.ViewDidLoad

    DatabaseConfiguration options = null;
    Database database = null;
	Replicator replicator = null;
    public void DoTest()
	{
		
		try
		{
            Database.Log.Console.Domains = LogDomain.All;
            Database.Log.Console.Level = LogLevel.Verbose;

            options = new DatabaseConfiguration
			{
				Directory = "."
			};
			database = new Database("MyTest", options);
			Console.WriteLine("Database opened ok");
		}
		catch (Exception e)
		{
			Console.WriteLine("Failed to open database: " + e.Message);
			return;
		}
		//	Prove the database works by saving and loading a document.
		var id = System.Guid.NewGuid().ToString();
		var doc = new MutableDocument(id);
		doc.SetBoolean("b", true);
		doc.SetInt("i", 1024);
		database.Save(doc);
		var newdoc = database.GetDocument(id);
		if (newdoc is null)
		{
			Console.WriteLine("Failed to write/read from the database");
			return;
		}

		//	Lets start the sync engine.
		try
		{
			var url = new Uri("ws://localhost:4984/testdb");
			var target = new URLEndpoint(url);
			var auth = new BasicAuthenticator("8afA2PdF8qYS", "the-password");
			var sync_config = new ReplicatorConfiguration(database, target)
			{
				ReplicatorType = ReplicatorType.PushAndPull,
				Continuous = true,
				Authenticator = auth,
				ConflictResolver = null,
			};
			replicator = new Replicator(sync_config);
			var listenerToken = replicator.AddChangeListener(SyncStatusUpdate);

			Console.WriteLine("StartSyncAgent: Using url: " + url);
			replicator.Start();
			Console.WriteLine("Completed startup");
		}
		catch (Exception e)
		{
			Console.WriteLine("Got exception");
		}
	}

	public void SyncStatusUpdate(object? sender, ReplicatorStatusChangedEventArgs e)
	{
		var changes = (int)e.Status.Progress.Total;
		var completed = (int)e.Status.Progress.Completed;

		Console.WriteLine("SyncStatusUpdate for changes {0}, completed {1}, status {2}",
			changes, completed, e?.Status.Activity);

        if (e?.Status.Error != null)
        {
            Console.WriteLine($"Error :: {e?.Status.Error}");
        }
    }

I’m not a Sync Gateway guy - but the first thing I would check is if something is listening on the host:port you are trying to open. You can test that something is listening on a port with curl (or browser) - see “To confirm that Sync Gateway is running” on Postman Collections for Sync Gateway Administration - The Couchbase Blog

curl http://localhost:4984

It should give a welcome message. If it gives “Connection Refused”, then nothing is listening. If it hangs - then you have some other connectivity issue - if AWS, then likely the your ip address is not allowed to connect (which won’t be the case for localhost).

Hi @mreiche, thanks for the notes. I realise I probably didn’t give enough information originally. I am pretty experienced with SG, so I have definitely tested the endpoint with curl. I use the SG REST interface for some functions, and I have used my unit tests to hit that interface, which works. I have also tested using the curl command you provide and that works too.

I think the problem might be related to the exception that MacProxy is throwing. I can’t seem to get the inner exception on it (I’ve tried setting a breakpoint on exceptions, to no avail).

Maybe this post will help c# - Couchbase.Lite fails to replicate - Stack Overflow

I can spin up an SG on my local machine, and the app still won’t connect to it (even though I can via curl). The possible issue they were highlighting was routing over an SSH tunnel, which is not the case here. Thx.

I think you’ve already found the issue here:

Why is that simple program generating an exception in MacProxy (BTW - I think that MacProxy has some bad paths - see here )

Perhaps, although I’ve had a previous discussion with @borrrden on this. He doesn’t think it would cause the problem. Further, why am I affected when I am guessing that no-one else is (I mean, I can’t even create a minimal .net 6/7 app and use SG). Something seems off.

I’ve already forgotten what discussions we had on this, but if you can send a repro app I can look and see what is happening. If possible I’d like to see exactly what exception is being thrown. It may be a change in Ventura, I am still not running it actually (too much stuff breaks every time I update macOS so I resist) but if your repro works fine on my machine that is an area for exploration.

I thoroughly agree about upgrading too soon. I sure am regretting it now.
I’m just packaging up a project to send you.