From 53d942dad1bc7d6d1a27511f2b8bab29523fee43 Mon Sep 17 00:00:00 2001 From: UlyssesWu Date: Wed, 26 Apr 2023 20:37:40 +0800 Subject: [PATCH 1/2] prevent `AggregateException` when connecting to unity process --- .../dnSpy.Debugger.DotNet.Mono/Impl/DbgEngineImpl.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet.Mono/Impl/DbgEngineImpl.cs b/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet.Mono/Impl/DbgEngineImpl.cs index 6a53695a45..6b5ac6b498 100644 --- a/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet.Mono/Impl/DbgEngineImpl.cs +++ b/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet.Mono/Impl/DbgEngineImpl.cs @@ -424,13 +424,19 @@ void StartCore(DebugProgramOptions options) { var cts = new CancellationTokenSource(connectionTimeout - elapsedTime); var asyncConn = VirtualMachineManager.ConnectAsync(endPoint, null, cts.Token); if (!asyncConn.Wait(connectionTimeout - elapsedTime)) - throw new CouldNotConnectException(GetCouldNotConnectErrorMessage(connectionAddress, connectionPort, filename)); + throw new CouldNotConnectException( + GetCouldNotConnectErrorMessage(connectionAddress, connectionPort, filename)); vm = asyncConn.Result; break; } catch (SocketException sex) when (sex.SocketErrorCode == SocketError.ConnectionRefused) { // Retry it in case it takes a while for mono.exe to initialize or if it hasn't started yet } + catch (AggregateException aex) when (aex.InnerExceptions.All(ex => ex is SocketException { + SocketErrorCode: SocketError.ConnectionRefused + })) { + // Retry it in case it takes a while + } Thread.Sleep(100); } From ed37dc02a7a100df43a3275b086e0a3eb72308bc Mon Sep 17 00:00:00 2001 From: Ulysses Wu Date: Thu, 27 Apr 2023 02:16:53 +0800 Subject: [PATCH 2/2] review fix --- .../dnSpy.Debugger.DotNet.Mono/Impl/DbgEngineImpl.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet.Mono/Impl/DbgEngineImpl.cs b/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet.Mono/Impl/DbgEngineImpl.cs index 6b5ac6b498..2b707fdcd0 100644 --- a/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet.Mono/Impl/DbgEngineImpl.cs +++ b/Extensions/dnSpy.Debugger/dnSpy.Debugger.DotNet.Mono/Impl/DbgEngineImpl.cs @@ -424,17 +424,14 @@ void StartCore(DebugProgramOptions options) { var cts = new CancellationTokenSource(connectionTimeout - elapsedTime); var asyncConn = VirtualMachineManager.ConnectAsync(endPoint, null, cts.Token); if (!asyncConn.Wait(connectionTimeout - elapsedTime)) - throw new CouldNotConnectException( - GetCouldNotConnectErrorMessage(connectionAddress, connectionPort, filename)); + throw new CouldNotConnectException(GetCouldNotConnectErrorMessage(connectionAddress, connectionPort, filename)); vm = asyncConn.Result; break; } catch (SocketException sex) when (sex.SocketErrorCode == SocketError.ConnectionRefused) { // Retry it in case it takes a while for mono.exe to initialize or if it hasn't started yet } - catch (AggregateException aex) when (aex.InnerExceptions.All(ex => ex is SocketException { - SocketErrorCode: SocketError.ConnectionRefused - })) { + catch (AggregateException aex) when (aex.InnerExceptions.Count == 1 && aex.InnerExceptions[0] is SocketException {SocketErrorCode: SocketError.ConnectionRefused}) { // Retry it in case it takes a while } Thread.Sleep(100);