diff options
author | Mauro Agnoletti <mauro.agnoletti@gmail.com> | 2022-05-03 18:55:07 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-03 18:55:07 +0300 |
commit | b34ca92ccaa1075d3e4424846654339b13b412d9 (patch) | |
tree | 0e65ef15d37d49acb941cf002960786d4881234a | |
parent | cdf25369c56e6006f64b63fd3ea4d817c2cf8da8 (diff) |
Protect from errors related to cancelling debugger connection (#361)dev/gregm/test
* Protect from null AsyncState when canceling the connection in VirtualMachineManager
Under some circumstances it could happen that the AsyncState is null because the socket connection was not established and the socket is therefore null.
This may happen when the debugger session has been started but the connection to the app didn't take place
* Added exception handling when canceling debugger connection on SoftDebuggerSession.EndLaunch
If any unexpected error occurs at this point, some important things may not happen like invoking the TargetExited event, which could cause the debugger session to hang
For this reason we should handle any exception happening here and report it accordingly
One reason for this problem to reproduce is when the debugger session launches but the connection with the app is not established, so the session will never end and potentially hang under any UI interaction
-rw-r--r-- | Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachineManager.cs | 4 | ||||
-rw-r--r-- | Mono.Debugging.Soft/SoftDebuggerSession.cs | 16 |
2 files changed, 13 insertions, 7 deletions
diff --git a/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachineManager.cs b/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachineManager.cs index f6bfd94..5bc2435 100644 --- a/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachineManager.cs +++ b/Mono.Debugger.Soft/Mono.Debugger.Soft/VirtualMachineManager.cs @@ -338,7 +338,9 @@ namespace Mono.Debugger.Soft public static void CancelConnection (IAsyncResult asyncResult) { - ((Socket)asyncResult.AsyncState).Close (); + //AsyncState could be null if the debugger incoming connection doesn't happen, so there's no socket between debugger and debuggee + //This could occur if the debugger session started but the connection to the app failed at some point + ((Socket)asyncResult.AsyncState)?.Close (); } public static VirtualMachine Connect (Connection transport, StreamReader standardOutput, StreamReader standardError) diff --git a/Mono.Debugging.Soft/SoftDebuggerSession.cs b/Mono.Debugging.Soft/SoftDebuggerSession.cs index fd22b2e..a173d25 100644 --- a/Mono.Debugging.Soft/SoftDebuggerSession.cs +++ b/Mono.Debugging.Soft/SoftDebuggerSession.cs @@ -386,12 +386,16 @@ namespace Mono.Debugging.Soft { HideConnectionDialog (); if (connection != null) { - if (startArgs != null && startArgs.ConnectionProvider != null) { - startArgs.ConnectionProvider.CancelConnect (connection); - startArgs = null; - } else { - VirtualMachineManager.CancelConnection (connection); - } + try {
+ if (startArgs != null && startArgs.ConnectionProvider != null) {
+ startArgs.ConnectionProvider.CancelConnect(connection);
+ startArgs = null;
+ } else {
+ VirtualMachineManager.CancelConnection(connection);
+ }
+ } catch(Exception e) {
+ DebuggerLoggingService.LogError("Unhandled error canceling the debugger connection", e);
+ }
connection = null; } } |