Bug 30046 - App hangs when clicking button after a directory is deleted that was being watched by FileSystemWatcher
Summary: App hangs when clicking button after a directory is deleted that was being wa...
Status: RESOLVED ANSWERED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Other ()
Version: 2.0.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Chris Hamons
URL:
Depends on:
Blocks:
 
Reported: 2015-05-13 14:53 UTC by Jon Goldberger [MSFT]
Modified: 2015-05-13 16:37 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test Project (25.27 KB, application/zip)
2015-05-13 14:53 UTC, Jon Goldberger [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Jon Goldberger [MSFT] 2015-05-13 14:53:53 UTC
Created attachment 11188 [details]
Test Project

## Description

App hangs with spinning beach ball when clicking a button after deleting a directory that was being watched by FileSystemWatcher. The app hangs on the button click before even the first line of the button event handler is executed, IOW a breakpoint on the first line of the button's event handler is not hit when clicking the button after directory deletion.

## Steps to reproduce:

1. Open the attached test project and set the FSW project (Xam.Mac project) to be the startup project.

2. Create a new folder somewhere on the file system that you can delete.

3. Run the FSW project.

4. Click "Select folder" and select the folder created in step 2.

5. Click "Delete folder" to delete the folder.

6. Press either the "Select folder" or "Delete folder" button.

Expected result: The NSopen panel will open if "Select folder" clicked, or nothing will happen if the "Delete folder" is clicked. App will not hang. 

Actual result: App hangs with spin dump below:

## Notes

I commented out some code I used to try to workaround the issue, and if that code is commented in the steps to reproduce above will work and will deliver the expected results, but this does not count for directories being deleted from outside of the app so there is a bug here that needs to be addressed. I also filed a Mono bug discovered at the same time as this bug. 
See bug https://bugzilla.xamarin.com/show_bug.cgi?id=30043


## Spin dump report:

>Date/Time:       2015-05-13 08:51:21 -1000
>OS Version:      10.10.3 (Build 14D136)
>Architecture:    x86_64h
>Report Version:  21
>
>Command:         FSW
>Path:            /Users/USER/Downloads/*/FSW.app/Contents/MacOS/FSW
>Version:         1.0 (1)
>PID:             77708
>
>Event:           timeout-lite
>Duration:        9.90s (process was unresponsive for 2 seconds before sampling)
>Steps:           100 (100ms sampling interval)
>
>Hardware model:  iMac14,1
>Active cpus:     4
>
>Fan speed:       1400 rpm
>
>Heaviest stack for the main thread of the target process:
>  100  start + 52 (Departments + 7220) [0x100001c34]
>  100  main + 800 (launcher.m:539,8 in Departments + 43264) [0x10000a900]
>  100  mono_main + 7911 (driver.g.c:1070,3 in Departments + 374903) [0x10005b877]
>  100  mono_runtime_exec_main + 376 (object.c:4119,9 in Departments + 1729928) [0x1001a6588]
>  100  mono_runtime_invoke + 110 (object.c:2862,11 in Departments + 1707390) [0x1001a0d7e]
>  100  mono_jit_runtime_invoke + 1673 (mini.c:6669,9 in Departments + 1058585) [0x100102719]
>  100  ??? [0x107d99d65]
>  100  ??? [0x107d9a071]
>  100  NSApplicationMain + 1832 (AppKit + 13140) [0x7fff860b8354]
>  100  -[NSApplication run] + 711 (AppKit + 552040) [0x7fff8613bc68]
>  100  -[NSApplication sendEvent:] + 2504 (AppKit + 1430290) [0x7fff86212312]
>  100  -[NSWindow sendEvent:] + 470 (AppKit + 1445238) [0x7fff86215d76]
>  100  -[NSWindow _reallySendEvent:isDelayedEvent:] + 14125 (AppKit + 8196860) [0x7fff868862fc]
>  100  -[NSControl mouseDown:] + 714 (AppKit + 2520166) [0x7fff8631c466]
>  100  -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 770 (AppKit + 2888799) [0x7fff8637645f]
>  100  -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2821 (AppKit + 2526643) [0x7fff8631ddb3]
>  100  _os_activity_initiate + 75 (libsystem_trace.dylib + 3287) [0x7fff91fd5cd7]
>  100  -[NSCell _sendActionFrom:] + 144 (AppKit + 2533567) [0x7fff8631f8bf]
>  100  _os_activity_initiate + 75 (libsystem_trace.dylib + 3287) [0x7fff91fd5cd7]
>  100  __26-[NSCell _sendActionFrom:]_block_invoke + 131 (AppKit + 2533730) [0x7fff8631f962]
>  100  -[NSControl sendAction:to:] + 86 (AppKit + 2533958) [0x7fff8631fa46]
>  100  -[NSApplication sendAction:to:from:] + 452 (AppKit + 2445233) [0x7fff86309fb1]
>  100  _os_activity_initiate + 75 (libsystem_trace.dylib + 3287) [0x7fff91fd5cd7]
>  100  xamarin_x86_64_common_trampoline + 110 (trampolines-x86_64-asm.s:54 in Departments + 42298) [0x10000a53a]
>  100  xamarin_arch_trampoline + 193 (trampolines-x86_64.m:540,2 in Departments + 36977) [0x100009071]
>  100  xamarin_invoke_trampoline + 467 (trampolines-invoke.m:74,10 in Departments + 30659) [0x1000077c3]
>  100  ??? [0x618000048b20]
>  100  process_single_step + 16 (debugger-agent.c:5056,2 in Departments + 235680) [0x1000398a0]
>  100  process_signal_event + 87 (debugger-agent.c:4852,2 in Departments + 259527) [0x10003f5c7]
>  100  suspend_current + 202 (debugger-agent.c:3025,9 in Departments + 245898) [0x10003c08a]
>  100  __psynch_cvwait + 10 (libsystem_kernel.dylib + 90422) [0x7fff87a72136]
> *100  psynch_cvcontinue + 0 (pthread + 26908) [0xffffff7f8106191c]
>
>  Binary Images:
>         0x100000000 -        0x10034dfff  com.your-company.Departments (1)    <9CF6BE81-2161-3CAA-8169-C2B0803D7A6B>  /Users/USER/*/Departments.app/Contents/MacOS/Departments
>      0x7fff860b5000 -     0x7fff86c36fff  com.apple.AppKit 6.9 (1347.57)      <B214D528-7D1C-39B2-BE36-821D417A0297>  /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit
>      0x7fff87a5c000 -     0x7fff87a79fff  libsystem_kernel.dylib (2782.20.48) <EAFD7BD0-0C30-3E7D-9528-F9916BA0167C>  /usr/lib/system/libsystem_kernel.dylib
>      0x7fff91fd5000 -     0x7fff91fdbfff  libsystem_trace.dylib (72.20.1)     <840F5301-B55A-3078-90B9-FEFFD6CD741A>  /usr/lib/system/libsystem_trace.dylib
> *0xffffff7f8105b000 - 0xffffff7f81063fff  com.apple.kec.pthread 1.0 (1)       <8365956C-8613-3ED4-BC64-0D8570D2089F>  /System/Library/Extensions/pthread.kext/Contents/MacOS/pthread
> 

## Environment

=== Xamarin Studio ===

Version 5.9.1 (build 3)
Installation UUID: 2dc9022f-f9a8-424f-8284-bf224cbbfde0
Runtime:
	Mono 4.0.0 ((detached/d136b79)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400000143

=== Apple Developer Tools ===

Xcode 6.3.1 (7703)
Build 6D1002

=== Xamarin.Mac ===

Version: 2.0.0.262 (Business Edition)

=== Xamarin.Android ===

Version: 5.1.0.115 (Business Edition)
Android SDK: /Users/apple/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.iOS ===

Version: 8.10.0.267 (Business Edition)
Hash: 6481535
Branch: master
Build date: 2015-04-27 04:38:13-0400

=== Build Information ===

Release ID: 509010003
Git revision: aad75a6e7e48f18120ce41f47d0ff2c6216f49c3
Build date: 2015-05-08 12:46:18-04
Xamarin addins: 1246b3044cbb7f56a217334f8fc5489ef8eefe3f

=== Operating System ===

Mac OS X 10.10.3
Darwin Jons-iMac.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Comment 1 Chris Hamons 2015-05-13 16:37:10 UTC
I'm actually seeing it crash this way locally:


Unhandled Exception:
System.ArgumentOutOfRangeException: Argument is out of range.
Parameter name: startIndex
  at System.String.Substring (Int32 startIndex) [0x0001b] in /Library/Frameworks/Xamarin.Mac.framework/Versions/2.0.0.262/src/mono/mcs/class/corlib/System/String.cs:427 
  at System.IO.KqueueMonitor.PostEvent (FileAction action, System.String path, System.String newPath) [0x00016] in /Library/Frameworks/Xamarin.Mac.framework/Versions/2.0.0.262/src/mono/mcs/class/System/System.IO/KeventWatcher.cs:579 
  at System.IO.KqueueMonitor.Remove (System.IO.PathData pathData) [0x00030] in /Library/Frameworks/Xamarin.Mac.framework/Versions/2.0.0.262/src/mono/mcs/class/System/System.IO/KeventWatcher.cs:464 
  at System.Collections.Generic.List`1[System.IO.PathData].ForEach (System.Action`1 action) [0x00035] in /Library/Frameworks/Xamarin.Mac.framework/Versions/2.0.0.262/src/mono/external/referencesource/mscorlib/system/collections/generic/list.cs:593 
  at System.IO.KqueueMonitor.Monitor () [0x001e8] in /Library/Frameworks/Xamarin.Mac.framework/Versions/2.0.0.262/src/mono/mcs/class/System/System.IO/KeventWatcher.cs:404 
  at System.IO.KqueueMonitor.DoMonitor () [0x00047] in /Library/Frameworks/Xamarin.Mac.framework/Versions/2.0.0.262/src/mono/mcs/class/System/System.IO/KeventWatcher.cs:268 

I am 99% sure that when mono fixes their bug (https://bugzilla.xamarin.com/show_bug.cgi?id=30043) and XM issues you are seeing will go away. In general, when mono crashes / throws exceptions internally things don't tend to go well for XM afterwords.
Comment 2 Chris Hamons 2015-05-13 16:37:41 UTC
When this is fixed, if you happen to see any more strangeness, please re-open or file another bug.