C# .NET application exits with code 139 on Mac but not Windows

I am attempting to setup replication between a .NET (8.0.403) C# application using Couchbase Lite (3.2.0), and a Couchbase Server + Couchbase Sync Gateway running in docker containers on the same machine (M3 Mac). The replication code is as follows:

// Get the database (and create it if it doesn't exist)
var database = new Database("mydb");
var collection = database.GetDefaultCollection();

// Create replicator to push and pull changes to and from
var targetEndpoint = new URLEndpoint(new Uri("ws://localhost:4984/audit"));
var replConfig = new ReplicatorConfiguration(targetEndpoint);
replConfig.AddCollection(database.CreateCollection("projects", "audit"));

// Add authentication
replConfig.Authenticator = new BasicAuthenticator("user@fake.com", "passwordFake");
replConfig.Continuous = true;
replConfig.ReplicatorType = ReplicatorType.PushAndPull;

// Create replicator
var replicator = new Replicator(replConfig);
replicator.AddChangeListener(OnReplicatorUpdate);

try {
    replicator.Start(); //THIS LINE FAILS
} catch (Exception e) {
    Console.WriteLine(e);
}

However the call to replicator.Start() results in the following error message:
Process finished with exit code 139. with no other error or warning logs and the application quits. I am running the console app via Jetbrains Rider and dotnet run.

This same code and docker setup works on a Windows 10 machine.

Additionally, after changing this code to connect to a Couchbase Capella instance, it continues to exit with the same error on Mac, but succeeds on Windows

This same simple application also works on my M3 Mac when written in Java rather than .NET C#

How can I have the replication succeed on a M3 Mac.

Full stacktrace:

2024-10-22 01:05:38.759-04:00 [1]| INFO)  [Database] (Startup) [1] CouchbaseLite/3.2.0 (.NET; Darwin 23.6.0 Darwin Kernel Version 23.6.0: Wed Jul 31 20:48:04 PDT 2024; root:xnu-10063.141.1.700.5~1/RELEASE_ARM64_T6030) Build/141 LiteCore/3.2.0 (224) Commit/1b16cd92
2024-10-22 01:05:38.819-04:00 [1]| WARNING)  [Database] (Logging) [1] Database.Log.File.Config is null, meaning file logging is disabled.  Log files required for product support are not being generated.
2024-10-22 01:05:38.819-04:00 [1]| INFO)  [Database] (Database) [1] Opening  database at /redacted/consoleTodo/bin/Debug/net8.0/CouchbaseLite/mydb.cblite2
2024-10-22 01:05:38.821-04:00 [1]| INFO)  [Database] {Shared#1}==> litecore::DataFile::Shared 0x102e09558 @0x102e09558
2024-10-22 01:05:38.821-04:00 [1]| INFO)  [Database] Obj=/Shared#1/ Path=/redacted/consoleTodo/bin/Debug/net8.0/CouchbaseLite/mydb.cblite2/db.sqlite3 Instantiated
2024-10-22 01:05:38.821-04:00 [1]| DEBUG)  [Database] Obj=/Shared#1/ created for DataFile 0x102e0f290 at /redacted/consoleTodo/bin/Debug/net8.0/CouchbaseLite/mydb.cblite2/db.sqlite3
2024-10-22 01:05:38.821-04:00 [1]| INFO)  [Database] {DB#2}==> litecore::SQLiteDataFile /redacted/consoleTodo/bin/Debug/net8.0/CouchbaseLite/mydb.cblite2/db.sqlite3 @0x102e0f290
2024-10-22 01:05:38.821-04:00 [1]| INFO)  [Database] Obj=/DB#2/ File=Shared#1 Opening database
2024-10-22 01:05:38.823-04:00 [1]| INFO)  [Database] {Collection#3}==> litecore::CollectionImpl mydb/_default @0x600003c6c4d0
2024-10-22 01:05:38.823-04:00 [1]| INFO)  [Database] Obj=/Collection#3/ DB=DB#2 Instantiated
2024-10-22 01:05:38.824-04:00 [1]| VERBOSE)  [Database] Obj=/DB#2/ Next expiration time is 0
2024-10-22 01:05:38.824-04:00 [1]| VERBOSE)  [Database] Obj=/DB#2/ Next expiration time is 0
2024-10-22 01:05:38.824-04:00 [1]| VERBOSE)  [Database] Obj=/DB#2/ Next expiration time is 0
2024-10-22 01:05:38.824-04:00 [1]| VERBOSE)  [Database] Obj=/DB#2/ Next expiration time is 0
2024-10-22 01:05:38.825-04:00 [1]| INFO)  [Database] {Collection#4}==> litecore::CollectionImpl mydb/projects @0x600003c6c5f0
2024-10-22 01:05:38.825-04:00 [1]| INFO)  [Database] Obj=/Collection#4/ DB=DB#2 Instantiated
2024-10-22 01:05:38.832-04:00 [1]| VERBOSE)  [Replicator] (Database) [1] There is no saved HTTP cookies.
2024-10-22 01:05:38.837-04:00 [1]| INFO)  [Replicator] (Replicator) [1] Replicator[<*> ws://localhost:4984/audit]: Starting
2024-10-22 01:05:38.837-04:00 [1]| DEBUG)  [Database] Obj=/Shared#1/ adding DataFile 0x15260af30
2024-10-22 01:05:38.837-04:00 [1]| INFO)  [Database] {DB#5}==> litecore::SQLiteDataFile /redacted/consoleTodo/bin/Debug/net8.0/CouchbaseLite/mydb.cblite2/db.sqlite3 @0x15260af30
2024-10-22 01:05:38.837-04:00 [1]| INFO)  [Database] Obj=/DB#5/ File=Shared#1 Opening database
2024-10-22 01:05:38.837-04:00 [1]| INFO)  [Database] {Collection#6}==> litecore::CollectionImpl mydb/_default @0x600003c70320
2024-10-22 01:05:38.837-04:00 [1]| INFO)  [Database] Obj=/Collection#6/ DB=DB#5 Instantiated
2024-10-22 01:05:38.837-04:00 [1]| VERBOSE)  [Database] Obj=/DB#5/ Next expiration time is 0
2024-10-22 01:05:38.837-04:00 [1]| VERBOSE)  [Database] Obj=/DB#5/ Next expiration time is 0
2024-10-22 01:05:38.838-04:00 [1]| VERBOSE)  [Database] Obj=/DB#5/ Next expiration time is 0
2024-10-22 01:05:38.838-04:00 [1]| VERBOSE)  [Database] Obj=/DB#5/ Next expiration time is 0
2024-10-22 01:05:38.838-04:00 [1]| INFO)  [Network] {Connection#7}==> litecore::blip::Connection ->ws://localhost:4984/audit/_blipsync @0x600002061010
2024-10-22 01:05:38.838-04:00 [1]| INFO)  [Network] Obj=/Connection#7/ Opening connection...
2024-10-22 01:05:38.838-04:00 [1]| INFO)  [Network] {BLIPIO#8}==> litecore::blip::BLIPIO ->ws://localhost:4984/audit/_blipsync @0x15260bbc0
2024-10-22 01:05:38.838-04:00 [1]| INFO)  [Network] {C4Socket#9}==> litecore::repl::C4SocketImpl ws://localhost:4984/audit/_blipsync @0x15260b3e8
2024-10-22 01:05:38.838-04:00 [1]| INFO)  [Replicator] {DNRepl@102C112D8/C4RemoteRepl#10}==> litecore::C4RemoteReplicator 0x15260a1a0 @0x15260a1a0
2024-10-22 01:05:38.838-04:00 [1]| INFO)  [Replicator] {Repl#11}==> litecore::repl::Replicator ->ws://localhost:4984/audit/_blipsync @0x15260b900
2024-10-22 01:05:38.838-04:00 [1]| INFO)  [Replicator] {DBAccess#12}==> litecore::repl::DBAccess 0x15410cb38 @0x15410cb38
2024-10-22 01:05:38.838-04:00 [1]| INFO)  [Replicator] Obj=/DNRepl@102C112D8/C4RemoteRepl#10/Repl#11/ DB=DB#5 Instantiated {{Coll#0} "audit.projects": {"Push": continuous, "Pull": continuous, Options={autoPurge:true, headers:{}}}}
Options={auth:{, type:"Basic", username:"demo@example.com"}, autoPurge:true, headers:{}, maxRetries:2147483646}
2024-10-22 01:05:38.838-04:00 [1]| INFO)  [Database] {Collection#13}==> litecore::CollectionImpl mydb/projects @0x600003c60b00
2024-10-22 01:05:38.838-04:00 [1]| INFO)  [Database] Obj=/Collection#13/ DB=DB#5 Instantiated
2024-10-22 01:05:38.838-04:00 [1]| INFO)  [Replicator] {Pusher#14}==> litecore::repl::Pusher Repl#11 @0x15260bef0
2024-10-22 01:05:38.838-04:00 [1]| INFO)  [Replicator] {Inserter#15}==> litecore::repl::Inserter Repl#11 @0x15260c440
2024-10-22 01:05:38.838-04:00 [1]| INFO)  [Replicator] {RevFinder#16}==> litecore::repl::RevFinder Repl#11 @0x15260c5e0
2024-10-22 01:05:38.838-04:00 [1]| INFO)  [Replicator] {Puller#17}==> litecore::repl::Puller Repl#11 @0x15260c130
2024-10-22 01:05:38.838-04:00 [1]| VERBOSE)  [Replicator] Obj=/DNRepl@102C112D8/C4RemoteRepl#10/Repl#11/ Remote-DB ID 1 found for target <ws://localhost:4984/audit/_blipsync>
2024-10-22 01:05:38.838-04:00 [1]| VERBOSE)  [Replicator] Obj=/DNRepl@102C112D8/C4RemoteRepl#10/ C4RemoteRepl 0x15260a1a0 created Repl 0x15260b900
2024-10-22 01:05:38.838-04:00 [1]| INFO)  [Replicator] Obj=/DNRepl@102C112D8/C4RemoteRepl#10/ Starting Replicator Repl#11 with config: {{{Coll#0} "audit.projects": {"Push": continuous, "Pull": continuous, Options={autoPurge:true, headers:{}}}}
Options={auth:{, type:"Basic", username:"demo@example.com"}, autoPurge:true, headers:{}, maxRetries:2147483646}}

2024-10-22 01:05:38.838-04:00 [12]| VERBOSE)  [Query] RecordEnumerator 0x600003974218: (.audit.projects, 110 0)
2024-10-22 01:05:38.838-04:00 [13]| INFO)  [Network] Obj=/DNRepl@102C112D8/C4RemoteRepl#10/Repl#11/Connection#7/C4Socket#9/ Connecting...
2024-10-22 01:05:38.838-04:00 [12]| INFO)  [Replicator] Obj=/DNRepl@102C112D8/C4RemoteRepl#10/Repl#11/ Coll=0 Scanning for pre-existing conflicts...
2024-10-22 01:05:38.839-04:00 [12]| INFO)  [Replicator] Obj=/DNRepl@102C112D8/C4RemoteRepl#10/Repl#11/ Coll=0 Found 0 conflicted docs in 0.001 sec
2024-10-22 01:05:38.839-04:00 [12]| INFO)  [Replicator] Obj=/DNRepl@102C112D8/C4RemoteRepl#10/Repl#11/ Coll=0 No local checkpoint 'cp-GUNXeJTSVmKRxlFzNTNCbzbewinVwPjl2aEv5XpXYJY='
2024-10-22 01:05:38.839-04:00 [12]| INFO)  [Replicator] Obj=/DNRepl@102C112D8/C4RemoteRepl#10/Repl#11/ activityLevel=connecting: connectionState=1, savingChkpt=0
2024-10-22 01:05:38.839-04:00 [1]| INFO)  [Replicator] (Replicator) [1] Replicator[<*> ws://localhost:4984/audit] is Connecting, progress 0/0
2024-10-22 01:05:38.839-04:00 [1]| INFO)  [Replicator] (Replicator) [1] Replicator[<*> ws://localhost:4984/audit] is Connecting, progress 0/0
Connecting to Sync Gateway.
All documents synced.
2024-10-22 01:05:38.841-04:00 [1]| INFO)  [Query] {Query#18}==> litecore::SQLiteQuery SELECT * FROM audit.projects @0x6000037687f0
2024-10-22 01:05:38.841-04:00 [1]| INFO)  [Query] Obj=/Query#18/ Compiling N1QL query: SELECT * FROM audit.projects
2024-10-22 01:05:38.841-04:00 [1]| VERBOSE)  [Query] Obj=/Query#18/ N1QL query translated to: {"FROM":[{"COLLECTION":"projects","SCOPE":"audit"}],"WHAT":[["."]]}
2024-10-22 01:05:38.841-04:00 [1]| INFO)  [Query] Obj=/Query#18/ Compiled as SELECT fl_result(fl_root("audit.projects".body)) FROM "kv_.audit.projects" AS "audit.projects"
2024-10-22 01:05:38.841-04:00 [1]| INFO)  [Query] {QueryEnum#19}==> litecore::SQLiteQueryEnumerator 0x600003f6c378 @0x600003f6c378
2024-10-22 01:05:38.841-04:00 [1]| INFO)  [Query] Obj=/QueryEnum#19/ Created on {Query#18} with 0 rows (2 bytes) in 0.011ms
2024-10-22 01:05:38.842-04:00 [1]| INFO)  [Query] (QueryResultSet) [1] Beginning query enumeration (600002564b00)
2024-10-22 01:05:38.842-04:00 [1]| VERBOSE)  [Query] Obj=/QueryEnum#19/ END
2024-10-22 01:05:38.842-04:00 [1]| INFO)  [Query] (QueryResultSet) [1] End of query enumeration (600002564b00)
Number of rows :: 0
2024-10-22 01:05:38.844-04:00 [.NET TP Worker]| INFO)  [Replicator] (WebSocketWrapper) [.NET TP Worker (8)] c4Socket is retained, and reachability status monitor is starting.

Process finished with exit code 139.

139 is a segmentation fault. Do you have a core dump?

Are you looking for a core dump from a tool like dotnet-dump?

I was hoping that the OS would write out a file of a snapshot of the image when it exited that would include the pc that executed the instruction that caused the segmentation failt.

Will work on trying to get a core dump, added a full stack trace to the original post in the mean time.

MacOS is not a supported platform for console applications and is thus untested but I’m curious if the same thing happens with MAUI and Mac Catalyst which is a supported platform.

Also @mreiche is correct in that .net logs and dumps would not be useful here. A native stack trace would reveal the problem if symbols are present.

1 Like

Tried this code in a MAUI + Mac Catalyst application (on my M3 Mac), and am still getting a segmentation fault. Stacktrace is below with native stacktrace as well.

Native Crash Reporting
Got a SIGSEGV while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries  used by your application.

Native stacktrace:
0x101b5dc98 - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : mono_dump_native_crash_info
0x101b16cac - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : mono_handle_native_crash
0x101aa4c4c - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : mono_sigsegv_signal_handler_debug
0x180cd2584 - /usr/lib/system/libsystem_platform.dylib : _sigtramp
0xffff800180d1ef40 - Unknown
0x180d1ef40 - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : CFNumberGetValue
0x101b6e560 - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : do_icall
0x101b6ce44 - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : do_icall_wrapper
0x101b61870 - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : mono_interp_exec_method
0x101b5f410 - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : interp_runtime_invoke
0x101aa7df0 - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : mono_jit_runtime_invoke
0x101a484c0 - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : mono_runtime_invoke_checked
0x101a5cbf8 - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : start_wrapper
0x180ca1f94 - /usr/lib/system/libsystem_pthread.dylib : _pthread_start
0x180c9cd34 - /usr/lib/system/libsystem_pthread.dylib : thread_start

Basic Fault Address Reporting

Memory around native instruction pointer (0x180e53738):
0x180e53728  fd 03 00 91 61 00 f8 b6 20 00 80 52 3b 00 00 14  ....a... ..R;...
0x180e53738  29 00 40 f9 aa 72 36 90 4a b1 40 f9 28 01 2a 8a  ).@..r6.J.@.(.*.
0x180e53748  30 01 0a ea 40 01 00 54 f1 03 01 aa 31 5c ed f2  0...@..T....1\..
0x180e53758  30 1a c1 da f1 03 10 aa f1 47 c1 da 1f 02 11 eb  0........G......

Managed Stacktrace:

  at <unknown> <0xffffffff>
  at Couchbase.Lite.Support.IOSProxy:CFNumberGetValue <0x00028>
  at Couchbase.Lite.Support.IOSProxy:CreateProxyAsync <0x002dc>
  at <connectProxyAsync>d__40:MoveNext <0x00132>
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore:Start <0x0007a>
  at System.Runtime.CompilerServices.AsyncVoidMethodBuilder:Start <0x0000e>
  at Couchbase.Lite.Sync.WebSocketWrapper:connectProxyAsync <0x00074>
  at Couchbase.Lite.Sync.WebSocketWrapper:<Start>b__31_0 <0x00300>
  at Dispatch.SerialQueue:ProcessAsync <0x0017c>
  at System.Threading.Tasks.Task:InnerInvoke <0x00044>
  at <>c:<.cctor>b__281_0 <0x0001c>
  at System.Threading.ExecutionContext:RunFromThreadPoolDispatchLoop <0x00064>
  at System.Threading.Tasks.Task:ExecuteWithThreadLocal <0x00216>
  at System.Threading.Tasks.Task:ExecuteEntryUnsafe <0x0008a>
  at System.Threading.Tasks.Task:ExecuteFromThreadPool <0x00014>
  at System.Threading.ThreadPoolWorkQueue:DispatchWorkItem <0x00042>
  at System.Threading.ThreadPoolWorkQueue:DispatchItemWithAutoreleasePool <0x00054>
  at System.Threading.ThreadPoolWorkQueue:Dispatch <0x00382>
  at WorkerThread:WorkerDoWork <0x0003e>
  at WorkerThread:WorkerThreadStart <0x001b8>
  at System.Object:runtime_invoke_direct_void__this__ <0x000ea>
  at <unknown> <0x00000>

Native Crash Reporting

Got a SIGSEGV while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries  used by your application.

An error has occurred in the native fault reporting. Some diagnostic information will be unavailable.

Native stacktrace:

0x101b5dc98 - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : mono_dump_native_crash_info
0x101b16cac - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : mono_handle_native_crash
0x101aa4c4c - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : mono_sigsegv_signal_handler_debug
0x180cd2584 - /usr/lib/system/libsystem_platform.dylib : _sigtramp
0xffff800180d1ef40 - Unknown
0x180d1ef40 - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : CFNumberGetValue
0x101b6e560 - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : do_icall
0x101b6ce44 - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : do_icall_wrapper
0x101b61870 - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : mono_interp_exec_method
0x101b5f410 - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : interp_runtime_invoke
0x101aa7df0 - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : mono_jit_runtime_invoke
0x101a484c0 - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : mono_runtime_invoke_checked
0x101a5cbf8 - /redacted/bin/Debug/net8.0-maccatalyst/maccatalyst-arm64/TodoApp.app/Contents/MacOS/TodoApp : start_wrapper
0x180ca1f94 - /usr/lib/system/libsystem_pthread.dylib : _pthread_start
0x180c9cd34 - /usr/lib/system/libsystem_pthread.dylib : thread_start

Exiting early due to double fault.

Actually yes I’ve seen this before and this was fixed in 3.2.0. macOS changed the location of one of the native libraries Couchbase uses and so we had to adjust.

The above errors are from a project already using Couchbase.Lite 3.2.0. Also tried using Couchbase.Lite.Enterprise 3.2.0 and got the same errors. Not sure if this is a different issue, or an edge case related to the same fix.

I was able to previously run an application using 3.2.0 and mac catalyst. I am moving on to setting up a new testing solution for it so I’ll have another look today and see what I can find out.

I have run tests internally using replication in a real environment for our current 3.2.1 internal builds and nothing is crashing, so I can’t be sure what the problem is at this time. There have only been 4 commits since 3.2.0 so I doubt much has changed.