Closed johnconners closed 11 months ago
Additionally I'm seeing the Apple crash reporting logs with this callstack. In spite of being what looks like a CLR exception, I'm not able to catch them via AppDomain.CurrentDomain.UnhandledException, Runtime.MarshalManagedException or Runtime.MarshalObjectiveCException. And prior to the switch from Xamarin.Mac to .NET 7 I never had any crashes like this.
0 libsystem_kernel.dylib 0x00007ff81adb21e2 __pthread_kill + 10
1 libsystem_pthread.dylib 0x00007ff81ade9ee6 pthread_kill + 263 (pthread.c:1670)
2 libsystem_c.dylib 0x00007ff81ad10b45 abort + 123 (abort.c:118)
3 libcoreclr.dylib 0x000000010b097462 PROCAbort + 50
4 libcoreclr.dylib 0x000000010b097390 PROCEndProcess(void*, unsigned int, int) + 320
5 libcoreclr.dylib 0x000000010b1facd3 EEPolicy::HandleFatalError(unsigned int, unsigned long, char16_t const*, _EXCEPTION_POINTERS*, char16_t const*, char16_t const*) + 371
6 libcoreclr.dylib 0x000000010b2caa61 ProcessCLRException + 1073
7 libcoreclr.dylib 0x000000010b2cfb32 UnwindManagedExceptionPass1(PAL_SEHException&, _CONTEXT*) + 354
8 libcoreclr.dylib 0x000000010b2cfe83 DispatchManagedException(PAL_SEHException&, bool) + 67
9 libcoreclr.dylib 0x000000010b2c99e2 HandleHardwareException(PAL_SEHException*) + 658
10 libcoreclr.dylib 0x000000010b06562b SEHProcessException(PAL_SEHException*) + 315
11 libcoreclr.dylib 0x000000010b09e5fb PAL_DispatchException + 139
12 libcoreclr.dylib 0x000000010b09e283 PAL_DispatchExceptionWrapper + 10
13 ??? 0x00000001151a5c1d 0x0 + 4649016349
14 ??? 0x00000001151a7022 0x0 + 4649021474
15 ??? 0x000000011562807a 0x0 + 4653744250
16 ??? 0x00000001156275e5 0x0 + 4653741541
17 ??? 0x000000011562562d 0x0 + 4653733421
18 ??? 0x000000011561c849 0x0 + 4653697097
19 ??? 0x0000000115624e7d 0x0 + 4653731453
20 ??? 0x0000000115179648 0x0 + 4648834632
21 ??? 0x000000011517953e 0x0 + 4648834366
22 ??? 0x000000011503f7cb 0x0 + 4647548875
23 ??? 0x000000011503f558 0x0 + 4647548248
24 ??? 0x000000011562feb2 0x0 + 4653776562
25 libcoreclr.dylib 0x000000010b371f79 CallDescrWorkerInternal + 124
26 libcoreclr.dylib 0x000000010b1c31ff DispatchCallSimple(unsigned long*, unsigned int, unsigned long, unsigned int) + 223
27 libcoreclr.dylib 0x000000010b1d9738 ThreadNative::KickOffThread_Worker(void*) + 136
28 libcoreclr.dylib 0x000000010b18eb38 ManagedThreadBase_DispatchOuter(ManagedThreadCallState*) + 296
29 libcoreclr.dylib 0x000000010b18f0a0 ManagedThreadBase::KickOff(void (*)(void*), void*) + 32
30 libcoreclr.dylib 0x000000010b1d980a ThreadNative::KickOffThread(void*) + 170
31 libcoreclr.dylib 0x000000010b09c3c7 CorUnix::CPalThread::ThreadEntry(void*) + 407
32 libsystem_pthread.dylib 0x00007ff81adea1d3 _pthread_start + 125 (pthread.c:893)
33 libsystem_pthread.dylib 0x00007ff81ade5bd3 thread_start + 15 (:-1)
And below is a full crash log from Apple.
- Not sure, I'm catching this via Runtime.MarshalObjectiveCException in production, I cannot reproduce it locally
Can you capture Environmen.StackTrace in the Runtime.MarshalObjectiveCException event handler and see if that shows something useful?
Thanks @rolfbjarne I'll push out an update to do that. Might take a while to get the result as so far I've only had one crash reported back!
Thanks @rolfbjarne I'll push out an update to do that. Might take a while to get the result as so far I've only had one crash reported back!
OK, I'll mark this as need-info until then.
Hi @rolfbjarne, so I finally got another crash. I suspect it's related to their web connection as the apple crash reporter indicates more errors than I'm getting (my crash handling can only send back a log if there's a web connection at the time of the crash currently). Interestingly this time the error was:
[__NSSingleObjectArrayI URL]: unrecognized selector sent to instance 0x600000891810
Anyway, Environment.Stacktrace is below. I've got a ConcurrentBag\<Switcher> and am calling AsParallel().ForAll() on that list and calling the GetPhotos() method from each Switcher instance, I see it's in fact running concurrently but it's failing when making a web request to Google. It's on my list to swap out NSUrlConnection functionality for HttpClient now I'm on .NET 7, so I'm wondering if this callstack looks like an issue with NSUrlConnection.SendSynchronousRequest() or my use of AsParallel().ForAll() (which I'll note is an approach I've used for many years on Windows and Xamarin.Mac) or both. I'm only seeing this crash on Intel Macs from Xcode, haven't seen a single one on Apple silicon. May be a coincidence though.
Does anything jump out at you as amiss?
at System.Environment.get_StackTrace()
at BackgroundSwitcher.MainClass.<>c.
b__0_2(Object sender, MarshalObjectiveCExceptionEventArgs args)
at ObjCRuntime.Runtime.OnMarshalObjectiveCException(IntPtr, SByte)
at ObjCRuntime.Runtime.on_marshal_objectivec_exception(IntPtr, SByte, IntPtr*)
at ObjCRuntime.Messaging.NativeHandle_objc_msgSend_NativeHandle_NativeHandle_NativeHandle(IntPtr, IntPtr, NativeHandle, NativeHandle, NativeHandle)
at ObjCRuntime.Messaging.NativeHandle_objc_msgSend_NativeHandle_NativeHandle_NativeHandle(IntPtr, IntPtr, NativeHandle, NativeHandle, NativeHandle)
at Foundation.NSUrlConnection.SendSynchronousRequest(NSUrlRequest, NSUrlResponse& , NSError& )
at BackgroundSwitcher.WebConnection2.MakeRequest(String url, RequestHeaderModDelegate request_modifier, Nullable`1 timeout, Boolean protocol_errors_ok)
at BackgroundSwitcher.Google.GetResponseRaw(String url, JsonObject json)
at BackgroundSwitcher.Google.GetResponse(NameValueCollection parameters, JsonObject json)
at BackgroundSwitcher.Google.GetPhotosFromAlbum(String albumId)
at BackgroundSwitcher.GoogleSwitcher.GetPhotos()
at BackgroundSwitcher.SwitchEngine.<>c__DisplayClass5_0.b__1(SwitcherBase switcher)
at System.Linq.Parallel.ForAllOperator`1.ForAllEnumerator`1.MoveNext(TInput&, Int32&)
at System.Linq.Parallel.ForAllSpoolingTask`2.SpoolingWork()
at System.Linq.Parallel.SpoolingTaskBase.Work()
at System.Linq.Parallel.QueryTask.BaseWork(Object)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext, ContextCallback, Object)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task&, Thread )
at System.Threading.Tasks.ThreadPoolTaskScheduler.TryExecuteTaskInline(Task, Boolean)
at System.Threading.Tasks.TaskScheduler.TryRunInline(Task, Boolean)
at System.Threading.Tasks.Task.InternalRunSynchronously(TaskScheduler, Boolean)
at System.Linq.Parallel.QueryTask.RunSynchronously(TaskScheduler)
at System.Linq.Parallel.SpoolingTask.<>c__DisplayClass2_0`2.b__0()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext, ContextCallback, Object)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task&, Thread )
at System.Threading.Tasks.ThreadPoolTaskScheduler.TryExecuteTaskInline(Task, Boolean)
at System.Threading.Tasks.TaskScheduler.TryRunInline(Task, Boolean)
at System.Threading.Tasks.Task.InternalRunSynchronously(TaskScheduler, Boolean)
at System.Linq.Parallel.SpoolingTask.SpoolForAll[TInputOutput,TIgnoreKey](QueryTaskGroupState, PartitionedStream`2, TaskScheduler)
at System.Linq.Parallel.MergeExecutor`1.Execute[TKey](PartitionedStream`2, Boolean, ParallelMergeOptions, TaskScheduler, Boolean, CancellationState, Int32)
at System.Linq.Parallel.PartitionedStreamMerger`1.Receive[TKey](PartitionedStream`2)
at System.Linq.Parallel.ForAllOperator`1.WrapPartitionedStream[TKey](PartitionedStream`2, IPartitionedStreamRecipient`1, Boolean, QuerySettings)
at System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.ChildResultsRecipient.Receive[TKey](PartitionedStream`2)
at System.Linq.Parallel.ScanQueryOperator`1.ScanEnumerableQueryOperatorResults.GivePartitionedStream(IPartitionedStreamRecipient`1)
at System.Linq.Parallel.UnaryQueryOperator`2.UnaryQueryOperatorResults.GivePartitionedStream(IPartitionedStreamRecipient`1)
at System.Linq.Parallel.QueryOperator`1.GetOpenedEnumerator(Nullable`1, Boolean, Boolean, QuerySettings)
at System.Linq.Parallel.ForAllOperator`1.RunSynchronously()
at BackgroundSwitcher.SwitchEngine.NextImage(Object sender, DoWorkEventArgs e)
at BackgroundSwitcher.SwitchEngine.PerformAction(Object sender, DoWorkEventArgs e)
at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs)
at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object)
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread, ExecutionContext, ContextCallback, Object)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task&, Thread )
at System.Threading.ThreadPoolWorkQueue.DispatchItemWithAutoreleasePool(Object, Thread)
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
at System.Threading.Thread.StartCallback()
That comes from here:
but that's weird, because the selector isn't URL
, it's sendSynchronousRequest:returningResponse:error:
:
I'm guessing this is because the URL
selector is called in Apple's code somewhere, it's not something we're doing directly. I saw a few issues with our SendSynchronousRequest implementation, so I created a PR (#19458).
Also note that Apple's deprecated it: https://developer.apple.com/documentation/foundation/nsurlconnection/1411393-sendsynchronousrequest?language=objc
Ah I hadn't noticed sendSynchronousRequest was deprecated, I'll make the switch to HttpClient and see if that clears things up. Thanks for the info! :)
I recently ported my 9 year old macOS app from Xamarin.Mac to .NET 7. I've got a crash that looks like it's happening on a worker thread, rolled out logging for Runtime.MarshalObjectiveCException and got this error. Strange thing is I'm not using NSDateComponents directly in my code and the only place I deal with NSDate is via the (DateTime) cast of an NSDate (which I get from a PHAsset when getting photos from the Photos API) and via NSDateFormatter Parse() where I pass in a string and then again cast the result.
I can't see how I'd be passing URL to NSDateComponents or even how to figure out what's happening that causes the exception. Any idea as to what I should look at to diagnose the issue?
Steps to Reproduce
Expected Behavior
No error reported.
Actual Behavior
The error is reported.
Environment
Version information
``` Visual Studio Community 2022 for Mac Version 17.6.5 (build 417) Installation UUID: e35afd07-22d5-4ec4-b7b5-194c044cc040 Runtime .NET 7.0.3 (64-bit) Architecture: Arm64 Microsoft.macOS.Sdk 13.1.1007; git-rev-head:8afca776a0a96613dfb7200e0917bb57f9ed5583; git-branch:release/7.0.1xx-xcode14.2 NuGet Version: 6.4.0.117 .NET SDK (Arm64) SDK: /usr/local/share/dotnet/sdk/7.0.309/Sdks SDK Versions: 7.0.309 7.0.308 6.0.415 6.0.414 MSBuild SDKs: Not installed .NET Runtime (Arm64) Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 7.0.12 7.0.11 7.0.10 7.0.7 7.0.5 7.0.2 7.0.0 6.0.23 6.0.22 6.0.21 6.0.18 6.0.16 6.0.13 6.0.11 Updater Version: 11 Apple Developer Tools Xcode: 14.3 21812 Build: 14E222b Operating System Mac OS X 13.6.0 Darwin 22.6.0 Darwin Kernel Version 22.6.0 Fri Sep 15 13:41:28 PDT 2023 root:xnu-8796.141.3.700.8~1/RELEASE_ARM64_T6000 arm64 ```Native error and stack trace
Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[NSDateComponents URL]: unrecognized selector sent to instance 0x60000075a190