dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.43k stars 4.76k forks source link

Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR) #109930

Open vyacheslav-volkov opened 3 weeks ago

vyacheslav-volkov commented 3 weeks ago

Android framework version

net8.0-android

Affected platform version

NET 8.0.403

Description

I'm encountering an error in my application, but only in the release build. In debug mode, the application works without any issues, but in the release build, I get an error at the same point during certain actions. Since the project is commercial, I cannot provide the specific code.

signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10008

Steps to Reproduce

Run the application in release mode

Did you find any workaround?

No response

Relevant log output

2024-10-28 13:35:52.954 16507-16507 DEBUG                   pid-16507                            A  signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10008
2024-10-28 13:35:52.954 16507-16507 DEBUG                   pid-16507                            A      x0  0000000000010000  x1  0000007ff23d5ce0  x2  ffffffffffffffe0  x3  02000074c890b100
2024-10-28 13:35:52.954 16507-16507 DEBUG                   pid-16507                            A      x4  02000074c890b120  x5  0000000000000000  x6  0000007ff23d5a68  x7  00000073e8958000
2024-10-28 13:35:52.954 16507-16507 DEBUG                   pid-16507                            A      x8  0000000000000075  x9  0000007588338d80  x10 0000007ff23d5ce0  x11 0000000000000002
2024-10-28 13:35:52.954 16507-16507 DEBUG                   pid-16507                            A      x12 0000007588353740  x13 0000007ff23d7f90  x14 0000007ff23d5bac  x15 0000000000000001
2024-10-28 13:35:52.954 16507-16507 DEBUG                   pid-16507                            A      x16 0000007769050078  x17 0000007768fd9fb0  x18 0000007778990000  x19 0000007ff23d5ce0
2024-10-28 13:35:52.954 16507-16507 DEBUG                   pid-16507                            A      x20 0000000000010000  x21 00000073e86bad29  x22 00000073bac24278  x23 00000075e8406f10
2024-10-28 13:35:52.954 16507-16507 DEBUG                   pid-16507                            A      x24 00000074c890b108  x25 00000075e8ed02a8  x26 00000075e84c6790  x27 00000000000001ee
2024-10-28 13:35:52.954 16507-16507 DEBUG                   pid-16507                            A      x28 0000000000000241  x29 0000007ff23d5ca0
2024-10-28 13:35:52.954 16507-16507 DEBUG                   pid-16507                            A      lr  00000073e889aa4c  sp  0000007ff23d5ca0  pc  00000073e889a6c4  pst 0000000000000000
2024-10-28 13:35:52.954 16507-16507 DEBUG                   pid-16507                            A  backtrace:
2024-10-28 13:35:52.954 16507-16507 DEBUG                   pid-16507                            A        #00 pc 00000000002506c4  /data/app/~~wjcc1Wg6l4ADjoWSBeHaBQ==/com.enjin.mobile.wallet-lbMLBHQAEa-31C81eXWpRw==/split_config.arm64_v8a.apk!libmonosgen-2.0.so (BuildId: b429a6405c79e0852cf3694861f0a6c5234a833a)
2024-10-28 13:35:52.954 16507-16507 DEBUG                   pid-16507                            A        dotnet/android#1 pc 0000000000250a48  /data/app/~~wjcc1Wg6l4ADjoWSBeHaBQ==/com.enjin.mobile.wallet-lbMLBHQAEa-31C81eXWpRw==/split_config.arm64_v8a.apk!libmonosgen-2.0.so (BuildId: b429a6405c79e0852cf3694861f0a6c5234a833a)
2024-10-28 13:35:52.954 16507-16507 DEBUG                   pid-16507                            A        dotnet/android#2 pc 00000000002029f0  /data/app/~~wjcc1Wg6l4ADjoWSBeHaBQ==/com.enjin.mobile.wallet-lbMLBHQAEa-31C81eXWpRw==/split_config.arm64_v8a.apk!libmonosgen-2.0.so (mono_class_inflate_generic_method_full_checked+404) (BuildId: b429a6405c79e0852cf3694861f0a6c5234a833a)
2024-10-28 13:35:52.954 16507-16507 DEBUG                   pid-16507                            A        dotnet/android#3 pc 000000000014d7ec  /data/app/~~wjcc1Wg6l4ADjoWSBeHaBQ==/com.enjin.mobile.wallet-lbMLBHQAEa-31C81eXWpRw==/split_config.arm64_v8a.apk!libmonosgen-2.0.so (BuildId: b429a6405c79e0852cf3694861f0a6c5234a833a)
2024-10-28 13:35:52.954 16507-16507 DEBUG                   pid-16507                            A        dotnet/android#4 pc 000000000014de34  /data/app/~~wjcc1Wg6l4ADjoWSBeHaBQ==/com.enjin.mobile.wallet-lbMLBHQAEa-31C81eXWpRw==/split_config.arm64_v8a.apk!libmonosgen-2.0.so (BuildId: b429a6405c79e0852cf3694861f0a6c5234a833a)
2024-10-28 13:35:52.954 16507-16507 DEBUG                   pid-16507                            A        dotnet/android#5 pc 000000000022a27c  /data/app/~~wjcc1Wg6l4ADjoWSBeHaBQ==/com.enjin.mobile.wallet-lbMLBHQAEa-31C81eXWpRw==/split_config.arm64_v8a.apk!libmonosgen-2.0.so (BuildId: b429a6405c79e0852cf3694861f0a6c5234a833a)
2024-10-28 13:35:52.954 16507-16507 DEBUG                   pid-16507                            A        dotnet/android#6 pc 0000000000006514  <anonymous:7448b66000>

update: the fault address is always the same fault addr 0x10008

grendello commented 3 weeks ago

Can you extract libmonosgen-2.0.so for the arm64 architecture from your apk and upload it here? It will allow us to symbolize the stack trace and see where exactly the error happens. Thanks!

vyacheslav-volkov commented 3 weeks ago

Hi @grendello, thanks for the quick response, I have attached the file.

libmonosgen-2.0.so.zip

vyacheslav-volkov commented 3 weeks ago

I remembered there's another place in the application that crashes with the same error but with a different address and stack trace. It was commented out in the file I sent. I’ve uncommented it and uploaded a new file. Here’s the log of that error:

2024-10-28 20:58:17.565 27275-27275 DEBUG                   pid-27275                            A  signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xf2c952a5377b9a
2024-10-28 20:58:17.565 27275-27275 DEBUG                   pid-27275                            A      x0  00000075eafd6618  x1  00000075eafeea00  x2  0000000000000000  x3  0000000000000000
2024-10-28 20:58:17.565 27275-27275 DEBUG                   pid-27275                            A      x4  00000075783c9940  x5  0000000000000002  x6  0000000000000001  x7  0000000000000000
2024-10-28 20:58:17.565 27275-27275 DEBUG                   pid-27275                            A      x8  00000075eafd63f8  x9  0000000000018040  x10 000000000400318d  x11 0000000000000001
2024-10-28 20:58:17.565 27275-27275 DEBUG                   pid-27275                            A      x12 0000000000000000  x13 00000075eb003008  x14 00000073e84841da  x15 000038838c4e1750
2024-10-28 20:58:17.565 27275-27275 DEBUG                   pid-27275                            A      x16 00000073ec17eef0  x17 00000073ec081294  x18 0000007778990000  x19 00000075eafeea00
2024-10-28 20:58:17.565 27275-27275 DEBUG                   pid-27275                            A      x20 00000075eafd6618  x21 00000075eafd63f8  x22 00000075eafd63f8  x23 dcf2c952a5377b92
2024-10-28 20:58:17.565 27275-27275 DEBUG                   pid-27275                            A      x24 00000075783c96f4  x25 0000000000000000  x26 00000075eafeea00  x27 0000000000000000
2024-10-28 20:58:17.565 27275-27275 DEBUG                   pid-27275                            A      x28 00000073e84841f2  x29 0000007ff23d2000
2024-10-28 20:58:17.565 27275-27275 DEBUG                   pid-27275                            A      lr  00000073ebf4f824  sp  0000007ff23d1fb0  pc  00000073ec08130c  pst 0000000040000000
2024-10-28 20:58:17.565 27275-27275 DEBUG                   pid-27275                            A  backtrace:
2024-10-28 20:58:17.565 27275-27275 DEBUG                   pid-27275                            A        #00 pc 000000000020930c  /data/app/~~pv8wG7gwqpUyn-sk5ZB3hA==/com.enjin.mobile.wallet-E_iHGmtF1VNYtW4x2sL96A==/split_config.arm64_v8a.apk!libmonosgen-2.0.so (mono_method_can_access_field+120) (BuildId: b429a6405c79e0852cf3694861f0a6c5234a833a)
2024-10-28 20:58:17.565 27275-27275 DEBUG                   pid-27275                            A        dotnet/android#1 pc 00000000000d7820  /data/app/~~pv8wG7gwqpUyn-sk5ZB3hA==/com.enjin.mobile.wallet-E_iHGmtF1VNYtW4x2sL96A==/split_config.arm64_v8a.apk!libmonosgen-2.0.so (BuildId: b429a6405c79e0852cf3694861f0a6c5234a833a)
2024-10-28 20:58:17.566 27275-27275 DEBUG                   pid-27275                            A        dotnet/android#2 pc 00000000000ca444  /data/app/~~pv8wG7gwqpUyn-sk5ZB3hA==/com.enjin.mobile.wallet-E_iHGmtF1VNYtW4x2sL96A==/split_config.arm64_v8a.apk!libmonosgen-2.0.so (BuildId: b429a6405c79e0852cf3694861f0a6c5234a833a)
2024-10-28 20:58:17.566 27275-27275 DEBUG                   pid-27275                            A        dotnet/android#3 pc 00000000000e3f0c  /data/app/~~pv8wG7gwqpUyn-sk5ZB3hA==/com.enjin.mobile.wallet-E_iHGmtF1VNYtW4x2sL96A==/split_config.arm64_v8a.apk!libmonosgen-2.0.so (BuildId: b429a6405c79e0852cf3694861f0a6c5234a833a)
2024-10-28 20:58:17.566 27275-27275 DEBUG                   pid-27275                            A        dotnet/android#4 pc 00000000000bb2f8  /data/app/~~pv8wG7gwqpUyn-sk5ZB3hA==/com.enjin.mobile.wallet-E_iHGmtF1VNYtW4x2sL96A==/split_config.arm64_v8a.apk!libmonosgen-2.0.so (BuildId: b429a6405c79e0852cf3694861f0a6c5234a833a)
2024-10-28 20:58:17.566 27275-27275 DEBUG                   pid-27275                            A        dotnet/android#5 pc 00000000000bd934  /data/app/~~pv8wG7gwqpUyn-sk5ZB3hA==/com.enjin.mobile.wallet-E_iHGmtF1VNYtW4x2sL96A==/split_config.arm64_v8a.apk!libmonosgen-2.0.so (BuildId: b429a6405c79e0852cf3694861f0a6c5234a833a)
2024-10-28 20:58:17.566 27275-27275 DEBUG                   pid-27275                            A        dotnet/android#6 pc 00000000000c264c  /data/app/~~pv8wG7gwqpUyn-sk5ZB3hA==/com.enjin.mobile.wallet-E_iHGmtF1VNYtW4x2sL96A==/split_config.arm64_v8a.apk!libmonosgen-2.0.so (BuildId: b429a6405c79e0852cf3694861f0a6c5234a833a)
2024-10-28 20:58:17.566 27275-27275 DEBUG                   pid-27275                            A        dotnet/android#7 pc 00000000000c1a6c  /data/app/~~pv8wG7gwqpUyn-sk5ZB3hA==/com.enjin.mobile.wallet-E_iHGmtF1VNYtW4x2sL96A==/split_config.arm64_v8a.apk!libmonosgen-2.0.so (BuildId: b429a6405c79e0852cf3694861f0a6c5234a833a)
2024-10-28 20:58:17.566 27275-27275 DEBUG                   pid-27275                            A        dotnet/android#8 pc 0000000000152278  /data/app/~~pv8wG7gwqpUyn-sk5ZB3hA==/com.enjin.mobile.wallet-E_iHGmtF1VNYtW4x2sL96A==/split_config.arm64_v8a.apk!libmonosgen-2.0.so (BuildId: b429a6405c79e0852cf3694861f0a6c5234a833a)
2024-10-28 20:58:17.566 27275-27275 DEBUG                   pid-27275                            A        dotnet/android#9 pc 0000000000152f70  /data/app/~~pv8wG7gwqpUyn-sk5ZB3hA==/com.enjin.mobile.wallet-E_iHGmtF1VNYtW4x2sL96A==/split_config.arm64_v8a.apk!libmonosgen-2.0.so (BuildId: b429a6405c79e0852cf3694861f0a6c5234a833a)
2024-10-28 20:58:17.566 27275-27275 DEBUG                   pid-27275                            A        dotnet/android#10 pc 0000000000005500  <anonymous:776edd0000>

libmonosgen-2.0.so.zip

grendello commented 3 weeks ago

The symbolicated backtrace suggests your application throws some exception and the runtime trips over it, for some reason (locations presented in the same order as frames in the backtrace):

0x2506c4
collect_type_images
/__w/1/s/src/mono/mono/metadata/metadata.c:3112

0x250a48
collect_ginst_images
/__w/1/s/src/mono/mono/metadata/metadata.c:3051
collect_method_images
/__w/1/s/src/mono/mono/metadata/metadata.c:3093
mono_metadata_get_mem_manager_for_method
/__w/1/s/src/mono/mono/metadata/metadata.c:3343

0x2029f0
mono_class_inflate_generic_method_full_checked
/__w/1/s/src/mono/mono/metadata/class.c:1224

0x14d7ec
get_method_from_stack_frame
/__w/1/s/src/mono/mono/mini/mini-exceptions.c:935

0x14de34
mono_get_frame_info
/__w/1/s/src/mono/mono/mini/mini-exceptions.c:1506

0x22a27c
ves_icall_System_Diagnostics_StackFrame_GetFrameInfo
/__w/1/s/src/mono/mono/metadata/icall.c:7392

@vyacheslav-volkov if you are able to reproduce the segfault locally, please record it using the following commands from the VS developer prompt (or mac terminal):

$ adb shell setprop debug.mono.log default,assembly,mono_log_level=debug,mono_log_mask=all
$ adb logcat -G 64M
$ adb logcat -c
# Start and crash the application here, wait 10s and then:
$ adb logcat -d > log.txt

In the resulting log.txt file, look for a managed exception stacktrace, somewhere above the segfault line.

vyacheslav-volkov commented 3 weeks ago

thanks @grendello, will check soon, could you please check the second log?

grendello commented 3 weeks ago

The second backtrace symbolicates as follows:

0x20930c
mono_method_can_access_field
/__w/1/s/src/mono/mono/metadata/class.c:6304

0xd7820
mono_method_to_ir
/__w/1/s/src/mono/mono/mini/method-to-ir.c:9909

0xca444
inline_method
/__w/1/s/src/mono/mono/mini/method-to-ir.c:4820

0xe3f0c
mono_method_to_ir
/__w/1/s/src/mono/mono/mini/method-to-ir.c:7868

0xbb2f8
mini_method_compile
/__w/1/s/src/mono/mono/mini/mini.c:3498

0xbd934
mono_jit_compile_method_inner
/__w/1/s/src/mono/mono/mini/mini.c:4132

0xc264c
mono_jit_compile_method_with_opt
/__w/1/s/src/mono/mono/mini/mini-runtime.c:2824
jit_compile_method_with_opt_cb
/__w/1/s/src/mono/mono/mini/mini-runtime.c:2879
jit_compile_method_with_opt
/__w/1/s/src/mono/mono/mini/mini-runtime.c:2895

0xc1a6c
mono_jit_compile_method
/__w/1/s/src/mono/mono/mini/mini-runtime.c:2914

0x152278
common_call_trampoline
/__w/1/s/src/mono/mono/mini/mini-trampolines.c:628

0x152f70
mono_vcall_trampoline
/__w/1/s/src/mono/mono/mini/mini-trampolines.c:850

It's a different issue. This one makes me wonder if it's a case of the linker removing too much.

vyacheslav-volkov commented 3 weeks ago

do I need to create a new issue for the second case?

@grendello I checked logs and I see a lot of different errors like this for different types:

10-28 21:10:10.493 28529 28806 I monodroid-assembly: typemap: unable to find mapping to a managed type from Java type 'java/nio/MappedByteBuffer' (hash 0x5e265317cf1553)
10-28 21:10:10.494 28529 28806 W monodroid-assembly: typemap: called from
10-28 21:10:10.494 28529 28806 W monodroid-assembly: at Java.Interop.TypeManager.GetJavaToManagedType(String )
10-28 21:10:10.494 28529 28806 W monodroid-assembly:    at Java.Interop.TypeManager.CreateInstance(IntPtr , JniHandleOwnership , Type )
10-28 21:10:10.494 28529 28806 W monodroid-assembly:    at Java.Lang.Object.GetObject(IntPtr , JniHandleOwnership , Type )
10-28 21:10:10.494 28529 28806 W monodroid-assembly:    at Java.Lang.Object._GetObject[Buffer](IntPtr , JniHandleOwnership )
10-28 21:10:10.494 28529 28806 W monodroid-assembly:    at Java.Lang.Object.GetObject[Buffer](IntPtr handle, JniHandleOwnership transfer)
10-28 21:10:10.494 28529 28806 W monodroid-assembly:    at MyApp.ExtensionsGetBuffer(IntPtr ptr, Int32 size)

But this is just warnings, I don't see any real exceptions.

vyacheslav-volkov commented 3 weeks ago

@grendello, I tried several times on the emulator and the device and information about the real exception is not written to the log. Any other suggestions on how to catch the exception?

vyacheslav-volkov commented 3 weeks ago

@grendello I've roughly located where the error occurs, it's a standard OperationCanceledException. There are several try-catch blocks in the stack trace, and everything works fine in debug mode. However, in release mode, the native code cannot retrieve the stack trace and crashes, even though the application has no unhandled exceptions. How is this possible?

vyacheslav-volkov commented 3 weeks ago

@grendello I need your help to find the reason I can't release the app as it crashes frequently (same code on iOS NativeAOT works without any problem). I have this code:

    private async Task RefreshAsync(IReadOnlyMetadataContext? metadata, CancellationToken cancellationToken)
    {
#if ANDROID
        cancellationToken = default; //todo hack for https://github.com/dotnet/runtime/issues/109930
#endif
        UpdateBalances(await INetworkManager.Instance.GetBalanceAsync(Address, metadata, cancellationToken).ConfigureAwait(false));
    }

if I ignore cancellationToken it will work, there is a try/catch in this code up the stack but even if I explicitly add it to the code it will fail:

    private async Task RefreshAsync(IReadOnlyMetadataContext? metadata, CancellationToken cancellationToken)
    {
        try
        {
              UpdateBalances(await INetworkManager.Instance.GetBalanceAsync(Address, metadata, cancellationToken).ConfigureAwait(false));
        }
        catch
        {
        }
    }
jonpryor commented 1 week ago

@vyacheslav-volkov: part of me wonders if an async void method is involved, mostly because RefreshAsync() is async, but doesn't await the return value of UpdateBalances().

vyacheslav-volkov commented 1 week ago

Hi @jonpryor, I'll add more context. RefreshAsync is used by the command, the command already has a try catch handler.

  RefreshCommand = CompositeCommand.Create(this, RefreshAsync).ToCommand();

The UpdateBalances is a fully synchronous method designed only to update a UI collection:

 private void UpdateBalances(PooledReadOnlyList<Balance> balances, CancellationToken cancellationToken)

This code doesn't use async void. I'm pretty sure the crash occurred at runtime since the same code works correctly in debug and iOS debug/release (NativeAOT). Are there ways to catch this and figure out what's wrong?

grendello commented 6 days ago

@vyacheslav-volkov Debug mode uses the interpreter, the code isn't JIT-ed - can you try running the app in Debug mode but with the UseInterpreter MSBuild property set to false?

vyacheslav-volkov commented 6 days ago

@grendello thanks, this helped to get a managed stack trace:

Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10008 in tid 18032 (app), pid 18032 (app)

=================================================================
    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.
=================================================================

No native Android stacktrace (see debuggerd output).

=================================================================
    Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x7b665686c4):0x7b665686b4  04 00 00 14 88 02 40 f9 08 01 40 f9 14 e1 02 91  ......@...@.....
0x7b665686c4  88 0a 40 b9 68 00 c0 36 89 12 40 b9 c9 04 00 35  ..@.h..6..@....5
0x7b665686d4  08 5d 10 53 08 3d 00 51 1f 3d 00 71 e8 07 00 54  .].S.=.Q.=.q...T
0x7b665686e4  a9 fe ff 10 aa 6a 68 38 29 09 0a 8b 20 01 1f d6  .....jh8)... ...

=================================================================
    Managed Stacktrace:
=================================================================
      at <unknown> <0xffffffff>
      at System.Diagnostics.StackFrame:GetFrameInfo <0x00007>
      at System.Diagnostics.StackFrame:BuildStackFrame <0x0017b>
      at System.Diagnostics.StackFrame:.ctor <0x000ab>
      at System.Diagnostics.StackTrace:InitializeForCurrentThread <0x0011f>
      at System.Diagnostics.StackTrace:.ctor <0x0008f>
      at System.Exception:SetCurrentStackTrace <0x00107>
      at System.Threading.Tasks.Task:GetExceptions <0x0010f>
      at System.Threading.Tasks.Task:ThrowIfExceptional <0x0007b>
      at System.Threading.Tasks.Task`1:GetResultCore <0x0017b>
      at System.Threading.Tasks.Task`1:get_Result <0x00177>
      at <>c:<TryInvokeImpl>b__2_0 <0x000a3>
      at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2:InnerInvoke <0x0017b>
      at <>c:<.cctor>b__281_0 <0x00097>
      at System.Threading.ExecutionContext:RunInternal <0x0026f>
      at System.Threading.Tasks.Task:ExecuteWithThreadLocal <0x002a3>
      at System.Threading.Tasks.Task:ExecuteEntryUnsafe <0x0014f>
      at System.Threading.Tasks.ThreadPoolTaskScheduler:TryExecuteTaskInline <0x0013b>
      at System.Threading.Tasks.TaskScheduler:TryRunInline <0x002b3>
      at System.Threading.Tasks.TaskContinuation:InlineIfPossibleOrElseQueue <0x001ab>
      at System.Threading.Tasks.ContinueWithTaskContinuation:Run <0x00357>
      at System.Threading.Tasks.Task:RunContinuations <0x004bf>
      at System.Threading.Tasks.Task:FinishContinuations <0x00117>
      at System.Threading.Tasks.Task:FinishStageThree <0x0010b>
      at System.Threading.Tasks.Task:CancellationCleanupLogic <0x00213>
      at System.Threading.Tasks.Task:TrySetCanceled <0x00107>
      at System.Threading.Tasks.Task:TrySetCanceled <0x0008f>
      at System.Threading.Tasks.TaskCompletionSource`1:TrySetCanceled <0x000af>
      at System.Threading.Tasks.TaskCompletionSource`1:TrySetCanceled <0x00093>
      at <>c:<.ctor>b__0_0 <0x0009f>
      at System.Threading.CancellationTokenSource:Invoke <0x000f3>
      at <>c:<ExecuteCallback>b__9_0 <0x000f7>
      at System.Threading.ExecutionContext:RunInternal <0x0026f>
      at CallbackNode:ExecuteCallback <0x00237>
      at System.Threading.CancellationTokenSource:ExecuteCallbackHandlers <0x00683>
      at System.Threading.CancellationTokenSource:NotifyCancellation <0x0009f>
      at System.Threading.CancellationTokenSource:Cancel <0x0008f>
      at System.Threading.CancellationTokenSource:Cancel <0x0006f>
      at MugenMvvm.Extensions.MugenExtensions:SafeCancel <0x00077>
      at MugenMvvm.Commands.CancelableCommandHandler:CancelAll <0x001cf>
      at MugenMvvm.Commands.CancelableCommandHandler:TryInvoke <0x00083>
a lot of stack frames from my app code

and native crash info:

signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10008
    x0  0000000000010000  x1  0000007fc6a802f0  x2  0000000000000060  x3  0000007fc6a805b0
    x4  0000007b4e2662c0  x5  0000000000000000  x6  0000007fc6a80078  x7  0000007b66626000
    x8  000000000000007b  x9  0000007b89a4c500  x10 0000007fc6a802f0  x11 0000000000000002
    x12 0000007b80308200  x13 0000007fc6a82dd0  x14 0000007fc6a801bc  x15 0000000000000001
    x16 0000007c0a030290  x17 0000007c09f5eff0  x18 0000000000000001  x19 0000007fc6a802f0
    x20 0000000000010000  x21 0000007b66388d29  x22 0000007b65e9ffb8  x23 0000007b802cd480
    x24 0000007b4e2662a8  x25 0000007b580ece50  x26 0000007b689abb30  x27 00000000000001ee
    x28 0000000000000241  x29 0000007fc6a802b0
    sp  0000007fc6a802b0  lr  0000007b66568a4c  pc  0000007b665686c4

backtrace:
    #00 pc 00000000002506c4  /data/app/com.enjin.mobile.wallet-XoiBlXIleoq0w4IuZb4wcw==/lib/arm64/libmonosgen-2.0.so
    dotnet/android#1 pc 0000000000250a48  /data/app/com.enjin.mobile.wallet-XoiBlXIleoq0w4IuZb4wcw==/lib/arm64/libmonosgen-2.0.so
    dotnet/android#2 pc 00000000002029f0  /data/app/com.enjin.mobile.wallet-XoiBlXIleoq0w4IuZb4wcw==/lib/arm64/libmonosgen-2.0.so (mono_class_inflate_generic_method_full_checked+404)
    dotnet/android#3 pc 000000000014d7ec  /data/app/com.enjin.mobile.wallet-XoiBlXIleoq0w4IuZb4wcw==/lib/arm64/libmonosgen-2.0.so
    dotnet/android#4 pc 000000000014de34  /data/app/com.enjin.mobile.wallet-XoiBlXIleoq0w4IuZb4wcw==/lib/arm64/libmonosgen-2.0.so
    dotnet/android#5 pc 000000000022a27c  /data/app/com.enjin.mobile.wallet-XoiBlXIleoq0w4IuZb4wcw==/lib/arm64/libmonosgen-2.0.so
    dotnet/android#6 pc 000000000001fe94  <anonymous:0000007b561b0000>

will it help you, do you need anything else?

grendello commented 6 days ago

@vyacheslav-volkov thanks, it looks much better! Is libmonosgen-2.0.so the same as the one you attached earlier? If not, please attach the current one

vyacheslav-volkov commented 6 days ago

it should be the same, but just in case attached the lib from the debug apk libmonosgen-2.0.so.zip

grendello commented 6 days ago

Thanks! OK, this is at least consistent with the earlier trace:

0x2506c4
collect_type_images
/__w/1/s/src/mono/mono/metadata/metadata.c:3112

0x250a48
collect_ginst_images
/__w/1/s/src/mono/mono/metadata/metadata.c:3051
collect_method_images
/__w/1/s/src/mono/mono/metadata/metadata.c:3093
mono_metadata_get_mem_manager_for_method
/__w/1/s/src/mono/mono/metadata/metadata.c:3343

0x2029f0
mono_class_inflate_generic_method_full_checked
/__w/1/s/src/mono/mono/metadata/class.c:1224

0x14d7ec
get_method_from_stack_frame
/__w/1/s/src/mono/mono/mini/mini-exceptions.c:935

0x14de34
mono_get_frame_info
/__w/1/s/src/mono/mono/mini/mini-exceptions.c:1506

0x22a27c
ves_icall_System_Diagnostics_StackFrame_GetFrameInfo
/__w/1/s/src/mono/mono/metadata/icall.c:7392

@steveisok I think this is another one for the runtime team, could you assign/move it as needed? Thanks!

dotnet-policy-service[bot] commented 6 days ago

Tagging subscribers to 'arch-android': @vitek-karas, @simonrozsival, @steveisok, @akoeplinger See info in area-owners.md if you want to be subscribed.

vyacheslav-volkov commented 4 days ago

Hi @steveisok, any updates\workarounds on this, it's a very critical issue for my application.

steveisok commented 4 days ago

@vyacheslav-volkov it's something we are looking into. Nothing to report now. If you have code to share, that would likely help us in the investigation.

vyacheslav-volkov commented 4 days ago

@steveisok this is a commercial project, unfortunately I can't send the code

steveisok commented 4 days ago

@steveisok this is a commercial project, unfortunately I can't send the code

Do you think you can generically represent some small sample?

vyacheslav-volkov commented 4 days ago

Unfortunately, no, because this only happens in one place and only when I switch tabs in the UI. I tried manually calling Cancel on the CancellationTokenSource, but it didn't help. The code keeps running, and the error is being handled.

grendello commented 4 days ago

@steveisok I wonder if native Java threads might be in play here? One that is unattached to the MonoVM instance might cause a crash?

kg commented 2 days ago

FYI, since ThrowIfExceptional is happening here and the crash appears to be while running continuations after cancellation, it's possible that you have code under your control that is awaiting the cancelled operation, and the cancellation is causing it to throw an OperationCancelledException. You could potentially rearrange your code a bit to await in a manner that does not throw/rethrow exceptions and then manually check to see whether it was cancelled, by using https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.configureawait?view=net-8.0#system-threading-tasks-task-configureawait(system-threading-tasks-configureawaitoptions) and setting the SuppressThrowing flag.

That might get you unblocked in the interim until we identify a root cause and fix for this issue.