Bug 41918 - [Cycle 7] Visual Studio crashes due to NullReferenceException in Renci.SshNet.BaseClient.Disconnect() if network connection is lost after deployment to simulator but before debugger connects
Summary: [Cycle 7] Visual Studio crashes due to NullReferenceException in Renci.SshNet...
Status: VERIFIED FIXED
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: iOS ()
Version: 4.1.0 (C7)
Hardware: PC Windows
: Normal normal
Target Milestone: 4.1.2 (C7SR1)
Assignee: Brendan Zagaeski (Xamarin Team, assistant)
URL:
Depends on:
Blocks:
 
Reported: 2016-06-17 01:25 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2016-10-19 18:49 UTC (History)
10 users (show)

Tags: BZRC7S1_C6SR4S1
Is this bug a regression?: Yes
Last known good build: Cycle 6 – Service Release 4


Attachments
Log files and detailed version info (12.38 KB, application/zip)
2016-06-17 01:25 UTC, Brendan Zagaeski (Xamarin Team, assistant)
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 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:
VERIFIED FIXED

Description Brendan Zagaeski (Xamarin Team, assistant) 2016-06-17 01:25:09 UTC
Created attachment 16373 [details]
Log files and detailed version info

[Cycle 7] Visual Studio crashes due to NullReferenceException in Renci.SshNet.BaseClient.Disconnect() if network connection is lost after deployment to simulator but before debugger connects




## Regression status: regression in Cycle 7

BAD:  XamarinVS 4.1.0.530 (2e39740) + Xamarin.iOS 9.8.0.323 (39ebb77)
GOOD: XamarinVS 4.0.4.4   (a9c7826) + Xamarin.iOS 9.6.2.4   (d8bedd0)




## Steps followed to replicate

1. Create a new "Visual C# > iOS > iPhone > Single View App (iPhone)" application.

2. Once VS is successfully connected to the Mac build host, select "Debug > Start Debugging".

3. Wait until the build completes.

4. As soon as the app launch screen appears on the simulator, quickly disconnect the network connection between the Mac build host and Windows.

5. Wait a few minutes for XamarinVS to notice that the build host connection has been lost.




## BAD Results (on Cycle 7)

Visual Studio terminates due to an unhandled exception:

> Application: devenv.exe
> Framework Version: v4.0.30319
> Description: The process was terminated due to an unhandled exception.
> Exception Info: System.NullReferenceException
>    at Renci.SshNet.BaseClient.Disconnect()
>    at Renci.SshNet.BaseClient.Dispose(Boolean)
>    at Xamarin.Messaging.Client.Ssh.SshMessagingConnection.Dispose(Boolean)
>    at Xamarin.Messaging.VisualStudio.MessagingService.Disconnect()
>    at Xamarin.Messaging.VisualStudio.MessagingService+<<MonitorConnectivity>b__114_0>d.MoveNext()
>    at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_1(System.Object)
>    at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object)
>    at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
>    at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
>    at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
>    at System.Threading.ThreadPoolWorkQueue.Dispatch()
>    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()




## GOOD Results (on Cycle 6)

Visual Studio keeps running despite the disconnection.  An error is displayed in the Output window:

> Launch failed. The app 'UnifiedSingleViewIphone1' could not be launched on 'iPhone 6 iOS 9.3'. Please check the logs for more details.

Visual Studio then exits Debug mode, allowing the user to try debugging again if desired.




## Additional version info (brief)

Visual Studio 2013 Update 3
Windows 8.1 (64-bit) in VMWare Fusion
Comment 2 Alan McGovern 2016-06-20 15:18:43 UTC
Alex has hit this issue and reported it last week.
Comment 3 Alex Corrado [MSFT] 2016-06-22 17:59:02 UTC
Yes, this looks similar to the issue I encountered during the WWDC party. I was able to reproduce it fairly reliably by using my iPhone personal hotspot as the router between my Mac and PC.

I got a slightly different stack trace:

>Xamarin.VisualStudio.IOS.XamarinIOSPackage Error: 0 : [2016-06-13 19:30:55.4961] An unhandled error occurred while executing a Mac Agent operation. Details: Safe handle has been closed

> System.ObjectDisposedException: Safe handle has been closed
>  at System.Threading.WaitHandle.WaitOneNative(SafeHandle waitableSafeHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
>  at System.Threading.WaitHandle.InternalWaitOne(SafeHandle waitableSafeHandle, Int64 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
>  at System.Threading.WaitHandle.WaitOne(Int32 millisecondsTimeout, Boolean exitContext)
>  at System.Threading.WaitHandle.WaitOne()
>  at Renci.SshNet.Session.Disconnect(DisconnectReason reason, String message)
>  at Renci.SshNet.Session.Disconnect()
>  at Renci.SshNet.BaseClient.Disconnect()
>  at Renci.SshNet.BaseClient.Dispose(Boolean disposing)
>  at Renci.SshNet.SshClient.Dispose(Boolean disposing)
>  at Xamarin.Messaging.Client.Ssh.MessagingSshClient.Dispose(Boolean disposing)
>  at Xamarin.Messaging.Client.Ssh.SshMessagingConnection.Dispose(Boolean disposing)
>  at Xamarin.Messaging.VisualStudio.MessagingService.Disconnect()
>  at Xamarin.Messaging.VisualStudio.MessagingService.<<MonitorConnectivity>b__114_0>d.MoveNext()
> --- End of stack trace from previous location where exception was thrown ---
>  at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_1(Object state)
>  at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
>  at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
>  at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
>  at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
>  at System.Threading.ThreadPoolWorkQueue.Dispatch()
>  at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
Comment 4 xamarin-release-manager 2016-06-24 15:45:39 UTC
Fixed in version 4.1.0.553 (cycle7)

Author: Jose Gallardo
Commit: 06d3e5babc1003a623e81cc1efebef5013b43be9 (xamarin/XamarinVS)
Comment 7 narayanp 2016-07-05 19:08:39 UTC
I have checked this issue with Xamarin.VisualStudio 4.1.0.550 and XI 9.8.2.11 of C7 trunk lane and observed that now the issue is working fine i.e, fixed have been merged in cycle 7 lane.

Hence, I am closing this issue.

Thanks!
Comment 8 Del Woodcock 2016-07-14 19:58:59 UTC
I am running the latest version, here is my version from the log: Xamarin Information: 0 : [2016-07-14 12:44:36.5631] Xamarin - 4.1.1.3-c7sr0+34a92cd
And I keep having the whole IDE crash when sitting there idle.

Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException
   at Renci.SshNet.BaseClient.Disconnect()
   at Renci.SshNet.BaseClient.Dispose(Boolean)
   at Xamarin.Messaging.Client.Ssh.SshMessagingConnection.Dispose(Boolean)
   at Xamarin.Messaging.VisualStudio.MessagingService.Disconnect()
   at Xamarin.Messaging.VisualStudio.MessagingService+<<MonitorConnectivity>b__114_0>d.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_1(System.Object)
   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
Comment 9 Brendan Zagaeski (Xamarin Team, assistant) 2016-07-19 17:54:28 UTC
@Del, if you'd like to try it, the candidate fix for this issue is included in the current beta channel version 4.1.0.550 ("Cycle 7 – Service Release 1").

(The version number of the "Cycle 7 – Service Release 1" XamarinVS Beta version is currently lower than the version number of "Cycle 7 – Service Release 0", but the build does include all of the changes from "Cycle 7 – Service Release 0". That bookkeeping issue will be corrected in a future build of "Cycle 7 – Service Release 1".)
Comment 10 Del Woodcock 2016-07-19 19:21:21 UTC
Brendan,

I will give it a try, thanks.
Comment 11 Alexandre Defalque 2016-10-19 06:59:01 UTC
The problem still exists with the latest version (4.2.0.703), see my comment in ticket 45346.
Comment 12 Brendan Zagaeski (Xamarin Team, assistant) 2016-10-19 18:49:58 UTC
The stack traces in Bug 45346 are different compared to Comment 0 and Comment 8.  Note for example that `BaseClient.Disconnect()` appears nowhere in Bug 45346.  It is unfortunate that multiple NullReferenceExceptions can arise in the connectivity process, but it is good that there is a separate bug report for those different stack traces.