Bug 57466 - Visual Studio sometimes hangs (pauses, freezes) when opening solutions, during `Xamarin.VisualStudio.ZeroConf.MacDiscoveryService.OnResolved()`
Summary: Visual Studio sometimes hangs (pauses, freezes) when opening solutions, durin...
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: XMA ()
Version: 4.5.0 (15.2)
Hardware: PC Windows
: Normal major
Target Milestone: 15.3
Assignee: Bugzilla
Depends on:
Reported: 2017-06-14 02:08 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2017-08-10 19:18 UTC (History)
11 users (show)

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

Test case (147.29 KB, application/zip)
2017-06-14 02:08 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Minidump (without heap) (1.12 MB, application/zip)
2017-06-14 02:11 UTC, Brendan Zagaeski (Xamarin Team, assistant)

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 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:

Description Brendan Zagaeski (Xamarin Team, assistant) 2017-06-14 02:08:30 UTC
Created attachment 22871 [details]
Test case

Visual Studio sometimes hangs (pauses, freezes) when opening solutions, during `Xamarin.VisualStudio.ZeroConf.MacDiscoveryService.OnResolved()`

## _Approximate_ steps to replicate

1. Update from Xamarin.VisualStudio to in Visual Studio 2017 or Visual Studio 2015.

2. Open the attached test case by double-clicking the solution file in Explorer or by right-clicking it and choosing Visual Studio from the "Open with menu item."  (Note: I suspect that any solution that contains an iOS app project could potentially hit this issue.)

3. In my tests, if the hang was going to happen, it always happened _before_ the "Preparing Solution" dialog appeared.

These steps to replicate were _not_ always sufficient to replicate the issue, but I have seen the hang:

- Once after updating from "Visual Studio 2017 version 15.2 (26430.12)" to "Visual Studio 2017 version 15.2 (26430.13)", with no involvement of the installer for Visual Studio 2015.

- Once in Visual Studio 2015 after updating Xamarin in a VM that _only_ had Visual Studio 2015 installed.

- Once in Visual Studio _2017_ after updating Visual Studio 2015 and 2013 to

It _feels_ like the issue might be related to some _systemwide_ after-effect of the update process, but I am not yet certain that the update process is actually even related to the behavior.  There were other similarities across all of the scenarios where I saw the hang, so the involvement of the update process might still be a coincidence.

## Results

The IDE gets stuck while opening the solution.

### Excerpt of the call stack of the Main Thread

> WindowsBase.dll!System.Windows.Threading.DispatcherSynchronizationContext.Wait(System.IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
> mscorlib.dll!System.Threading.SynchronizationContext.InvokeWaitMethodHelper(System.Threading.SynchronizationContext syncContext, System.IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
> [Native to Managed Transition]
> [Managed to Native Transition]
> Xamarin.VisualStudio.ZeroConf.dll!Xamarin.VisualStudio.ZeroConf.MacDiscoveryService.OnResolved(System.Collections.Generic.IReadOnlyList<Zeroconf.IZeroconfHost> hosts)
> Xamarin.VisualStudio.ZeroConf.dll!Xamarin.VisualStudio.ZeroConf.MacDiscoveryService.DiscoverHosts(object state)

### Suspicious additional threads all trying to run `MacDiscoveryService.OnResolved()`

The attached minidump (without heap) in the next comment shows that there are 70 additional threads all running `MacDiscoveryService.OnResolved()`.

## Testing environment info (brief)

### Windows

In my tests, Xamarin in Visual Studio always had valid login information already saved for the remote Mac.

Microsoft Visual Studio Enterprise 2017 
Version 15.2 (26430.13) Release
Microsoft .NET Framework
Version 4.7.02046

XamarinVS (fec6f88)

Windows 10 (64-bit) Version 1703 (OS Build 15063.332)
Local non-domain user
User name: "Windows User"
US English locale, US Eastern time zone

### Mac

Mono (2017-02/5077205)
Xamarin.iOS (d15-2: d2270eec)

Xcode 8.3, Build version 8E162
macOS 10.12.4
User name: "macuser"
US English locale, US Eastern time zone
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2017-06-14 02:11:52 UTC
Created attachment 22872 [details]
Minidump (without heap)
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2017-06-14 02:20:14 UTC
At the moment this report is based purely on my local observations.  I have not yet seen any user reports that match this symptom.  That said, it looks like this issue was introduced by the change to using the ZeroConf library, so it might be a good candidate for investigation in the near future while the integration of that new code is still recent.
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2017-06-14 23:50:02 UTC
Just to add one more data point, I saw this hang today during the first project load after I had updated my Visual Studio 2017 Preview instance to 15.3 Preview 2:

Microsoft Visual Studio Enterprise 2017 Preview (Pre)
Version 15.3.0 Preview 2.0

XamarinVS (cb14994)
Comment 5 mag@xamarin.com 2017-06-29 02:35:32 UTC
Assigning to joj for verification since he has recently added some fixes to avoid hangs and crashes on the new ZeroConf implementation
Comment 9 Alok Kulkarni 2017-07-17 12:47:35 UTC
Tried on latest builds for VS015 and VS2017 by performing mentioned steps, VS hang no longer exist while loading the solution.

Hence marking Verified Fixed to this issue.

Build info VS2015 : https://gist.github.com/alok-kulkarni/b9a11f678ea7cbe7b8e2d6d95efcffc4
ScreenCast VS2015 : https://www.screencast.com/t/ExqLkuIF

Build info VS2017 : https://gist.github.com/alok-kulkarni/6cc6c328aff02cc9f234ba77fca5ea95
ScreenCast VS2017 : https://www.screencast.com/t/npX7TDuoeNR
Comment 10 Ivan Shakhov 2017-07-20 08:58:52 UTC
Am I right that fix will land in VS15.3?
And what would be build of VS 2015?
Comment 11 mfulker 2017-08-10 19:18:02 UTC
I keep getting this problem in VS2017. Is there any workaround?

Microsoft Visual Studio Enterprise 2017 
Version 15.2 (26430.16) Release
Xamarin (fec6f88)