Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac app crashes while using FSEventStreamCreateFlags.UseExtendedData #12007

Closed
anoopvaidya opened this issue Jun 23, 2021 · 7 comments · Fixed by #14318
Closed

Mac app crashes while using FSEventStreamCreateFlags.UseExtendedData #12007

anoopvaidya opened this issue Jun 23, 2021 · 7 comments · Fixed by #14318
Labels
bug If an issue is a bug or a pull request a bug fix macOS Issues affecting Xamarin.Mac
Milestone

Comments

@anoopvaidya
Copy link

anoopvaidya commented Jun 23, 2021

Steps to Reproduce

Create a Mac project.
Use the following code :
_fsEventStream = new FSEventStream(new[] { path },
TimeSpan.FromSeconds(0),
FSEventStreamCreateFlags.UseExtendedData
);
Build and run the app, in the observed folder, rename or delete any file. The app crashes and gives the attached Crash report

Note: For all other Flags, the client works.

Expected Behavior

The app should work and give the callbacks.

Actual Behavior

The app crashes.

Environment

MacOS11.4
=== Visual Studio Community 2019 for Mac ===

Version 8.10.3 (build 15)
Installation UUID: c0925b23-6e9d-4b80-a12d-fddf5ddbeb32
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 6.18.0.23 (d16-6 / 088c736)

Package version: 612000140

=== Mono Framework MDK ===

Runtime:
Mono 6.12.0.140 (2020-02/51d876a041e) (64-bit)
Package version: 612000140

=== Roslyn (Language Service) ===

3.10.0-4.21269.26+029847714208ebe49668667c60ea5b0a294e0fcb

=== NuGet ===

Version: 5.9.0.7134

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/5.0.301/Sdks
SDK Versions:
5.0.301
5.0.203
5.0.202
5.0.100
3.1.410
3.1.409
3.1.408
3.1.404
MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
5.0.7
5.0.6
5.0.5
5.0.0
3.1.16
3.1.15
3.1.14
3.1.10

=== .NET Core 3.1 SDK ===

SDK: 3.1.410

=== Xamarin.Profiler ===

Version: 1.6.15.68
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Xamarin.Android ===

Not Installed

=== Microsoft OpenJDK for Mobile ===

Java SDK: Not Found

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.10.0.12
Hash: e240b8c
Branch: remotes/origin/d16-10
Build date: 2021-06-01 18:26:34 UTC

=== Android Device Manager ===

Version: 16.10.0.14
Hash: e340248
Branch: remotes/origin/d16-10
Build date: 2021-06-01 18:26:52 UTC

=== Xamarin Designer ===

Version: 16.10.0.119
Hash: 36a2d986f
Branch: remotes/origin/d16-10
Build date: 2021-06-02 19:41:34 UTC

=== Apple Developer Tools ===

Xcode 12.5 (18205)
Build 12E262

=== Xamarin.Mac ===

Version: 7.14.0.24 (Visual Studio Community)
Hash: c4b89cd
Branch: d16-10
Build date: 2021-06-15 22:03:00-0400

=== Xamarin.iOS ===

Xamarin.iOS not installed.
Can't find mtouch or the Version file at /Library/Frameworks/Xamarin.iOS.framework/Versions/Current.

=== Build Information ===

Release ID: 810030015
Git revision: 9579bfad0898e06fdd77b8f4127bdcb5412a5b38
Build date: 2021-06-17 13:42:21-04
Build branch: release-8.10

=== Operating System ===

Mac OS X 10.16.0
Darwin 20.5.0 Darwin Kernel Version 20.5.0
Sat May 8 05:10:33 PDT 2021
root:xnu-7195.121.3~9/RELEASE_X86_64 x86_64

Build Logs

=================================================================
Native Crash Reporting

Got a abrt 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:

0x1099dca26 - /Users/anoopvaidya/Documents/Project/Test.app/Contents/MacOS/Test : mono_dump_native_crash_info
0x1099d05fe - /Users/anoopvaidya/Documents/Project/Test.app/Contents/MacOS/Test : mono_handle_native_crash
0x1099dc02f - /Users/anoopvaidya/Documents/Project/Test.app/Contents/MacOS/Test : sigabrt_signal_handler
0x7fff20430d7d - /usr/lib/system/libsystem_platform.dylib : _sigtramp
0x7fff00000400 - Unknown
0x7fff20340411 - /usr/lib/system/libsystem_c.dylib : abort
0x7fff203aeef2 - /usr/lib/libc++abi.dylib : abort_message
0x7fff203a05fd - /usr/lib/libc++abi.dylib : _ZL29demangling_unexpected_handlerv
0x7fff2029958d - /usr/lib/libobjc.A.dylib : _ZL15_objc_terminatev
0x7fff203ae307 - /usr/lib/libc++abi.dylib : _ZSt11__terminatePFvvE
0x7fff203b0beb - /usr/lib/libc++abi.dylib : __cxa_get_exception_ptr
0x7fff203b0bb2 - /usr/lib/libc++abi.dylib : _ZN10__cxxabiv1L22exception_cleanup_funcE19_Unwind_Reason_CodeP17_Unwind_Exception
0x7fff20296ec0 - /usr/lib/libobjc.A.dylib : objc_exception_throw
0x7fff205e138d - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : -[NSObject(NSObject) __retain_OA]
0x7fff204c690b - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : forwarding
0x7fff204c62d8 - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : _CF_forwarding_prep_0
0x12073589b - Unknown
0x120735303 - Unknown
0x120735113 - Unknown
0x12073412f - Unknown
0x111a91c1b - Unknown
0x7fff271d10d1 - /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/FSEvents.framework/Versions/A/FSEvents : implementation_callback_rpc
0x7fff271d006e - /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/FSEvents.framework/Versions/A/FSEvents : _Xcallback_rpc
0x7fff271cff67 - /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/FSEvents.framework/Versions/A/FSEvents : FSEventsD2F_server
0x7fff271d34d7 - /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/FSEvents.framework/Versions/A/FSEvents : FSEventsClientProcessMessageCallback
0x7fff20511132 - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : __CFMachPortPerform
0x7fff204e5104 - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION
0x7fff204e4fe5 - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : __CFRunLoopDoSource1
0x7fff204e366f - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : __CFRunLoopRun
0x7fff204e264c - /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation : CFRunLoopRunSpecific
0x7fff28720ab3 - /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/HIToolbox : RunCurrentEventLoopInMode
0x7fff28720815 - /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/HIToolbox : ReceiveNextEventCommon
0x7fff287205b3 - /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/HIToolbox : _BlockUntilNextEventMatchingListInModeWithFilter
0x7fff22ce36f2 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : _DPSNextEvent
0x7fff22ce1ec5 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]
0x7fff22cd4239 - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : -[NSApplication run]
0x7fff22ca847c - /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit : NSApplicationMain
0x11211b987 - Unknown
0x11211b633 - Unknown
0x10c6148e3 - Unknown
0x10c614a81 - Unknown
0x1099e734e - /Users/anoopvaidya/Documents/Project/Test.app/Contents/MacOS/Test : mono_jit_runtime_invoke
0x109b1c458 - /Users/anoopvaidya/Documents/Project/Test.app/Contents/MacOS/Test : mono_runtime_invoke_checked
0x109b23785 - /Users/anoopvaidya/Documents/Project/Test.app/Contents/MacOS/Test : mono_runtime_exec_main_checked
0x10994371c - /Users/anoopvaidya/Documents/Project/Test.app/Contents/MacOS/Test : mono_jit_exec
0x109946816 - /Users/anoopvaidya/Documents/Project/Test.app/Contents/MacOS/Test : mono_main
0x1098d50cc - /Users/anoopvaidya/Documents/Project/Test.app/Contents/MacOS/Test : xamarin_main
0x1098d5f44 - /Users/anoopvaidya/Documents/Project/Test.app/Contents/MacOS/Test : main
0x7fff20406f5d - /usr/lib/system/libdyld.dylib : start

=================================================================
Telemetry Dumper:

Pkilling 0x123145570578432x from 0x4543233536x
Pkilling 0x123145590099968x from 0x4543233536x
Pkilling 0x123145596428288x from 0x4543233536x
Pkilling 0x123145602756608x from 0x4543233536x
Pkilling 0x123145609084928x from 0x4543233536x
Pkilling 0x123145615413248x from 0x4543233536x
Pkilling 0x123145579552768x from 0x4543233536x
Pkilling 0x123145566359552x from 0x4543233536x
Pkilling 0x123145562640384x from 0x4543233536x
Pkilling 0x123145585881088x from 0x4543233536x
Pkilling 0x123145572687872x from 0x4543233536x
Pkilling 0x123145592209408x from 0x4543233536x
Pkilling 0x123145598537728x from 0x4543233536x
Pkilling 0x123145604866048x from 0x4543233536x
Pkilling 0x123145611194368x from 0x4543233536x
Pkilling 0x123145617522688x from 0x4543233536x
Pkilling 0x123145581662208x from 0x4543233536x
Pkilling 0x123145587990528x from 0x4543233536x
Pkilling 0x123145574797312x from 0x4543233536x
Pkilling 0x123145594318848x from 0x4543233536x
Pkilling 0x123145600647168x from 0x4543233536x
Pkilling 0x123145606975488x from 0x4543233536x
Pkilling 0x123145613303808x from 0x4543233536x
Pkilling 0x123145577443328x from 0x4543233536x
Pkilling 0x123145560530944x from 0x4543233536x
Pkilling 0x123145583771648x from 0x4543233536x
Could not exec mono-hang-watchdog, expected on path
'/Users/anoopvaidya/Documents/Project/Test.app/Contents/MonoBundle/../bin/mono-hang-
watchdog' (errno 2)
Entering thread summarizer pause from 0x4543233536x
Finished thread summarizer pause from 0x4543233536x.
Failed to create breadcrumb file (null)/crash_hash_0x8b75d4582

Waiting for dumping threads to resume
2021-06-22 15:36:43.537 Test[41377:15453304] -[__NSDictionaryM length]: unrecognized
selector sent to instance 0x6000052814a0
2021-06-22 15:36:43.547 Test[41377:15453304] *** Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM length]:
unrecognized selector sent to instance 0x6000052814a0'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff2055e87b __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff20296d92 objc_exception_throw + 48
2 CoreFoundation 0x00007fff205e138d -[NSObject(NSObject) __retain_OA] + 0
3 CoreFoundation 0x00007fff204c690b forwarding + 1448
4 CoreFoundation 0x00007fff204c62d8 _CF_forwarding_prep_0 + 120
5 ??? 0x000000012073589b 0x0 + 4839397531
6 ??? 0x0000000120735303 0x0 + 4839396099
7 ??? 0x0000000120735113 0x0 + 4839395603
8 ??? 0x000000012073412f 0x0 + 4839391535
9 ??? 0x0000000111a91c1b 0x0 + 4591262747
10 FSEvents 0x00007fff271d10d1 implementation_callback_rpc + 4067
11 FSEvents 0x00007fff271d006e _Xcallback_rpc + 233
12 FSEvents 0x00007fff271cff67 FSEventsD2F_server + 55
13 FSEvents 0x00007fff271d34d7 FSEventsClientProcessMessageCallback + 46
14 CoreFoundation 0x00007fff20511132 __CFMachPortPerform + 250
15 CoreFoundation 0x00007fff204e5104 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 41
16 CoreFoundation 0x00007fff204e4fe5 __CFRunLoopDoSource1 + 619
17 CoreFoundation 0x00007fff204e366f __CFRunLoopRun + 2400
18 CoreFoundation 0x00007fff204e264c CFRunLoopRunSpecific + 563
19 HIToolbox 0x00007fff28720ab3 RunCurrentEventLoopInMode + 292
20 HIToolbox 0x00007fff28720815 ReceiveNextEventCommon + 587
21 HIToolbox 0x00007fff287205b3 _BlockUntilNextEventMatchingListInModeWithFilter + 70
22 AppKit 0x00007fff22ce36f2 _DPSNextEvent + 864
23 AppKit 0x00007fff22ce1ec5 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1364
24 AppKit 0x00007fff22cd4239 -[NSApplication run] + 586
25 AppKit 0x00007fff22ca847c NSApplicationMain + 816
26 ??? 0x000000011211b987 0x0 + 4598118791
27 ??? 0x000000011211b633 0x0 + 4598117939
28 ??? 0x000000010c6148e3 0x0 + 4502669539
29 ??? 0x000000010c614a81 0x0 + 4502669953
30 Test 0x00000001099e734e mono_jit_runtime_invoke + 1550
31 Test 0x0000000109b1c458 mono_runtime_invoke_checked + 136
32 Test 0x0000000109b23785 mono_runtime_exec_main_checked + 117
33 Test 0x000000010994371c mono_jit_exec + 364
34 Test 0x0000000109946816 mono_main + 8790
35 Test 0x00000001098d50cc xamarin_main + 1116
36 Test 0x00000001098d5f44 main + 36
37 libdyld.dylib 0x00007fff20406f5d start + 1
)
libc++abi: terminating with uncaught exception of type NSException

=================================================================
External Debugger Dump:

=================================================================
Basic Fault Address Reporting

Memory around native instruction pointer (0x7fff203bc92e):0x7fff203bc91e ff ff c3 90
90 90 b8 48 01 00 02 49 89 ca 0f 05 .......H...I....
0x7fff203bc92e 73 08 48 89 c7 e9 a1 a1 ff ff c3 90 90 90 b8 53 s.H............S
0x7fff203bc93e 00 00 02 49 89 ca 0f 05 73 08 48 89 c7 e9 89 a1 ...I....s.H.....
0x7fff203bc94e ff ff c3 90 90 90 b8 83 01 00 02 49 89 ca 0f 05 ...........I....

=================================================================
Managed Stacktrace:

at <0xffffffff>
at CoreFoundation.CFString:CFStringGetLength <0x000fa>
at CoreFoundation.CFString:FetchString <0x00172>
at CoreFoundation.CFString:ToString <0x00132>
at CoreServices.FSEventStream:EventsCallback <0x0055e>
at CoreServices.FSEventStream:EventsCallback <0x0015a>
at <0xffffffff>
at AppKit.NSApplication:NSApplicationMain <0x00276>
at AppKit.NSApplication:Main <0x00292>
at Sncr.Cloud.UI.Mac.MainClass:Main <0x00182>
at :runtime_invoke_void_object <0x00110>

Example Project (If Possible)

Some details : https://stackoverflow.com/questions/68097055/crash-while-using-fseventstreamcreateflags-useextendeddata

@rolfbjarne
Copy link
Member

I can reproduce.

This happens because the arguments we get in the callback are different when passing the UseExtendedData flag.

The documentation here says that the eventPaths argument will be a CFArrayRef, but we get an NSDictionary. It's only when looking in the header file and look for the comment for kFSEventStreamCreateFlagUseExtendedData we see that the argument will be different: "[...] and instructs the framework to invoke your callback function with CF types but, instead of passing it a CFArrayRef of CFStringRefs, a CFArrayRef of CFDictionaryRefs is passed."

Test project: xmtestapp-7c28c31.zip

@rolfbjarne rolfbjarne added bug If an issue is a bug or a pull request a bug fix macOS Issues affecting Xamarin.Mac labels Jun 24, 2021
@rolfbjarne rolfbjarne added this to the Future milestone Jun 24, 2021
@blindseykahua
Copy link

I'm seeing this using any of the flags. Not sure when it was introduced but it's bringing our app down. Any idea when this will get fixed?

@rolfbjarne
Copy link
Member

@blindseykahua: did it work for you at some point, or is this new code you're writing?

@blindseykahua
Copy link

We've been using it for a long time. Not sure when it broke though. If I had to guess maybe Sept/Oct?

@rolfbjarne
Copy link
Member

@blindseykahua ok, that's a different problem then, could you please file a new issue for it so that we can track and handle it correctly?

@blindseykahua
Copy link

You got it, dude:
#13442

@abock
Copy link
Contributor

abock commented Mar 4, 2022

Fixed in my PR. The .UseExtendedData causes the event data to change from a CFString to a CFDictionary. The dictionary contains the path and inode.

abock added a commit to abock/xamarin-macios that referenced this issue Mar 8, 2022
When UseExtendedData is specified, the event data type changes
from CFString to CFDictionary; the dictionary contains the path
and inode information for the file and may be extended in the future
with other fields. Previously this was crashing because we assumed
CFString always.

Adds file system tests which cover the existing (non-extended) and
fixed (extended) creation modes, along with using a dispatch queue
instead of run loop.

Fixes xamarin#12007
rolfbjarne pushed a commit that referenced this issue Mar 9, 2022
…tch queues (#12007) (#14318)

Implements support for `FSEventStreamCreateFlags.UseExtendedData`, fixing #12007.

When `.UseExtendedData` is specified, the event data type changes from `CFString` to `CFDictionary`; the dictionary contains the path (`path` key) and inode (`fileID` key) information for the file and may be extended in the future with other fields. Previously this was crashing because we assumed `CFString` always.

Further add a convenience constructor for monitoring a single path, add the missing `UnscheduleFromRunLoop` APIs, and add `SetDispatchQueue` to allow using dispatch queues directly instead of run loops.

Finally, this PR adds a fairly exhaustive file system test which covers the existing (non-extended) and fixed (extended) creation modes, along with using a dispatch queue instead of run loop.

Fixes #12007
@xamarin xamarin locked as resolved and limited conversation to collaborators Apr 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug If an issue is a bug or a pull request a bug fix macOS Issues affecting Xamarin.Mac
Projects
None yet
4 participants