Open tipa opened 6 months ago
According to @rolfbjarne from the .NET iOS/macOS team, CoreCLR (which is what is used on iOS when using Native AOT as well as on macOS) doesn't support
MarshalManagedExceptionMode.UnwindNativeCode
and therefore, this assertion is crashing the process:
Hm, I'm not sure I follow everything that's going on here but it seems like that assertion is also dependent on xamarin_is_gc_coop
, which is only true when TARGET_OS_WATCH
:
#if TARGET_OS_WATCH
bool xamarin_is_gc_coop = true;
#else
bool xamarin_is_gc_coop = false;
#endif
I can't see anything from Sentry in that stack trace though. Do you know what kind of exception was originally thrown (that resulted in this stack trace)?
I don' think it is dependent on xamarin_is_gc_coop
. I might have posted links from the wrong commit, this one shows how the xamarin_assertion_message
method is called in line 2441, like in the stack trace:
https://github.com/xamarin/xamarin-macios/blob/ed26faa94fe2734d9c1014d2e6ef7173d4d77690/runtime/runtime.m#L2441
and then abort()
in line 1461:
https://github.com/xamarin/xamarin-macios/blob/ed26faa94fe2734d9c1014d2e6ef7173d4d77690/runtime/runtime.m#L1461
I don't know what exception was originally thrown (that's what I'm trying to find out), @rolfbjarne recommended that I should also subscribe to the ObjCRuntime.Runtime.MarshalManagedException
event and then log the exception manually (more on that is documented here. UnwindNativeCode
is documented as This isn't available when [...] when using CoreCLR
).
OK thanks, that makes more sense. If we can find a way to throw an exception that reproduces this behaviour then we should be able to work out a solution 👍🏻
@jamescrosswell you can reproduce this behavior / stack trace by simply throwing an exception in the AppDelegate.FinishedLaunching
method in an NativeAot-compiled app. You might have to upload a build to TestFlight as (to my knowledge) it is not possible to run NativeAOT compiled iOS apps locally.
Since there will be more adoption of NativeAOT in the future (e.g. with the launch of .NET 9), would it be possible to optionally disable this part of the Sentry initialization, so that the unsupported marshalling behavior isn't used?
https://github.com/getsentry/sentry-dotnet/blob/bea3fcf35dc0a2787dbf9c96931ec9895989907c/src/Sentry/Platforms/Cocoa/SentrySdk.cs#L14-L17
would it be possible to optionally disable this part of the Sentry initialization
We could definitely put these on the Cocoa specific native options - like we do with the LogCat options for Android.
Upping the priority on this as it crashes the process.
Upping the priority on this as it crashes the process.
@bitsandfoxes what do we want to do about this?
you might have to upload a build to TestFlight as (to my knowledge) it is not possible to run NativeAOT compiled iOS apps locally.
Realistically, we can't test for things like this until/unless we create a developer profile and an app in the Apple store that we start down the QA route. Having done that once personally for a Flutter app, I suspect it's going to take about 3-5 days to get this all setup via CI so that we can easily deploy new versions of our app (e.g. Sentry.Samples.MAUI) to the iOS store... there are various encryption/deployment keys to manage that we'll need to sync between CI and our local machines etc.
I don't think we've got the bandwidth to do this right now. Perhaps once we've sorted out what we're going to do about net9.0 (and the device tests) we could circle back to this.
@bitsandfoxes what do we want to do about this?
Would it not be possible to allow an optional/temporary way to disable the changing of marshalling bahavior, as I suggested above? I don't know if it would really work, but at the moment, the stack traces are just barely understandable...
I was able to run a Native AOT compiled app locally on a physical device using dotnet publish /t:Run /p:_DeviceName=DEVICEID
where DEVICEID can be queried using xcrun xctrace list devices
I was able to run a Native AOT compiled app locally on a physical device using
dotnet publish /t:Run /p:_DeviceName=DEVICEID
where DEVICEID can be queried usingxcrun xctrace list devices
That helps... it means we don't have to push it all the way through to test flight. Just a bit of fluffing around setting up encryption keys, developer profiles and configuring an app in the apple dev portal.
So it sounds a little less painful, when we do have the bandwidth to look into this.
Package
Sentry
.NET Flavor
.NET
.NET Version
8.0.2
OS
iOS
SDK Version
4.2.1
Self-Hosted Sentry Version
No response
Steps to Reproduce
Crash in NativeAOT compiled iOS app (there might be more prerequisites, like the managed exception to be marshalled to native code and back to managed).
Expected Result
Crash with useful strack trace including managed C# function from where it originated
Actual Result
I believe this is caused because of this event handler that changes the default marshalling behavior of exceptions: https://github.com/getsentry/sentry-dotnet/blob/bea3fcf35dc0a2787dbf9c96931ec9895989907c/src/Sentry/Platforms/Cocoa/SentrySdk.cs#L14-L17
The code was introduced after this discussion in the Xamarin repo: https://github.com/xamarin/xamarin-macios/issues/15252
According to @rolfbjarne from the .NET iOS/macOS team, CoreCLR (which is what is used on iOS when using Native AOT as well as on macOS) doesn't support
MarshalManagedExceptionMode.UnwindNativeCode
and therefore, this assertion is crashing the process: https://github.com/xamarin/xamarin-macios/blob/907081f787315704a01c940cf28b46b47db23df0/runtime/runtime.m#L2362-L2364 https://github.com/xamarin/xamarin-macios/blob/907081f787315704a01c940cf28b46b47db23df0/runtime/runtime.m#L2452-L2455