From 8a35f87d35522010e9711be2bc619631b1f2d579 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Thu, 27 Sep 2018 15:16:38 -0400 Subject: [PATCH] Don't catch OperationCanceledExceptions Fix IRC connect always returning true --- .../Components/Byond/PosixByondInstaller.cs | 4 ++++ .../Components/Byond/WindowsByondInstaller.cs | 4 ++++ src/Tgstation.Server.Host/Components/Chat/Chat.cs | 4 ++++ .../Components/Chat/JsonTrackingContext.cs | 4 ++++ .../Components/Chat/Providers/DiscordProvider.cs | 12 ++++++++++++ .../Components/Chat/Providers/IrcProvider.cs | 9 +++++++++ .../Components/Compiler/DmbFactory.cs | 4 ++++ .../Components/Interop/CommContext.cs | 1 + .../Components/Watchdog/SessionController.cs | 4 ++++ .../Components/Watchdog/Watchdog.cs | 4 ++++ .../Controllers/InstanceController.cs | 3 ++- .../Security/WindowsSystemIdentityFactory.cs | 4 ++++ 12 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/Tgstation.Server.Host/Components/Byond/PosixByondInstaller.cs b/src/Tgstation.Server.Host/Components/Byond/PosixByondInstaller.cs index e26aab8da4..c467d4c08b 100644 --- a/src/Tgstation.Server.Host/Components/Byond/PosixByondInstaller.cs +++ b/src/Tgstation.Server.Host/Components/Byond/PosixByondInstaller.cs @@ -65,6 +65,10 @@ namespace Tgstation.Server.Host.Components.Byond { await ioManager.DeleteDirectory(ByondCachePath, cancellationToken).ConfigureAwait(false); } + catch (OperationCanceledException) + { + throw; + } catch (Exception e) { logger.LogWarning("Error deleting BYOND cache! Exception: {0}", e); diff --git a/src/Tgstation.Server.Host/Components/Byond/WindowsByondInstaller.cs b/src/Tgstation.Server.Host/Components/Byond/WindowsByondInstaller.cs index 5c1a83e18f..08098ab03a 100644 --- a/src/Tgstation.Server.Host/Components/Byond/WindowsByondInstaller.cs +++ b/src/Tgstation.Server.Host/Components/Byond/WindowsByondInstaller.cs @@ -92,6 +92,10 @@ namespace Tgstation.Server.Host.Components.Byond { await ioManager.DeleteDirectory(ioManager.ConcatPath(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "byond/cache"), cancellationToken).ConfigureAwait(false); } + catch(OperationCanceledException) + { + throw; + } catch (Exception e) { logger.LogWarning("Error deleting BYOND cache! Exception: {0}", e); diff --git a/src/Tgstation.Server.Host/Components/Chat/Chat.cs b/src/Tgstation.Server.Host/Components/Chat/Chat.cs index 191988addc..de28124c76 100644 --- a/src/Tgstation.Server.Host/Components/Chat/Chat.cs +++ b/src/Tgstation.Server.Host/Components/Chat/Chat.cs @@ -305,6 +305,10 @@ namespace Tgstation.Server.Host.Components.Chat if (result != null) await SendMessage(result, new List { message.User.Channel.RealId }, cancellationToken).ConfigureAwait(false); } + catch (OperationCanceledException) + { + throw; + } catch (Exception e) { //error bc custom commands should reply about why it failed diff --git a/src/Tgstation.Server.Host/Components/Chat/JsonTrackingContext.cs b/src/Tgstation.Server.Host/Components/Chat/JsonTrackingContext.cs index 1efa732ef9..1aee8b6ea7 100644 --- a/src/Tgstation.Server.Host/Components/Chat/JsonTrackingContext.cs +++ b/src/Tgstation.Server.Host/Components/Chat/JsonTrackingContext.cs @@ -82,6 +82,10 @@ namespace Tgstation.Server.Host.Components.Chat return result; } } + catch (OperationCanceledException) + { + throw; + } catch (Exception e) { logger.LogWarning("Error retrieving custom commands! Exception: {0}", e); diff --git a/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs b/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs index d1a33aac23..70808ab9cc 100644 --- a/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs +++ b/src/Tgstation.Server.Host/Components/Chat/Providers/DiscordProvider.cs @@ -128,6 +128,10 @@ namespace Tgstation.Server.Host.Components.Chat.Providers using (cancellationToken.Register(() => channelsAvailable.SetCanceled())) await channelsAvailable.Task.ConfigureAwait(false); } + catch (OperationCanceledException) + { + throw; + } catch (Exception e) { logger.LogWarning("Error connecting to Discord: {0}", e); @@ -148,6 +152,10 @@ namespace Tgstation.Server.Host.Components.Chat.Providers cancellationToken.ThrowIfCancellationRequested(); await client.LogoutAsync().ConfigureAwait(false); } + catch (OperationCanceledException) + { + throw; + } catch (Exception e) { logger.LogWarning("Error disconnecting from discord: {0}", e); @@ -204,6 +212,10 @@ namespace Tgstation.Server.Host.Components.Chat.Providers CancelToken = cancellationToken }) ?? Task.CompletedTask).ConfigureAwait(false); } + catch (OperationCanceledException) + { + throw; + } catch (Exception e) { logger.LogWarning("Error sending discord message: {0}", e); diff --git a/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs b/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs index 12374f26fd..ea2ff03a1c 100644 --- a/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs +++ b/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs @@ -304,9 +304,14 @@ namespace Tgstation.Server.Host.Components.Chat.Providers client.Listen(); }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); } + catch (OperationCanceledException) + { + throw; + } catch (Exception e) { logger.LogWarning("Unable to connect to IRC: {0}", e); + return false; } return true; }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); @@ -332,6 +337,10 @@ namespace Tgstation.Server.Host.Components.Chat.Providers Dispose(); await listenTask.ConfigureAwait(false); } + catch (OperationCanceledException) + { + throw; + } catch (Exception e) { logger.LogWarning("Error disconnecting from IRC! Exception: {0}", e); diff --git a/src/Tgstation.Server.Host/Components/Compiler/DmbFactory.cs b/src/Tgstation.Server.Host/Components/Compiler/DmbFactory.cs index 8b830e8fa7..86d6fb1fd7 100644 --- a/src/Tgstation.Server.Host/Components/Compiler/DmbFactory.cs +++ b/src/Tgstation.Server.Host/Components/Compiler/DmbFactory.cs @@ -264,6 +264,10 @@ namespace Tgstation.Server.Host.Components.Compiler ++deleting; await ioManager.DeleteDirectory(x, cancellationToken).ConfigureAwait(false); } + catch (OperationCanceledException) + { + throw; + } catch (Exception e) { logger.LogWarning("Error deleting directory {0}! Exception: {1}", x, e); diff --git a/src/Tgstation.Server.Host/Components/Interop/CommContext.cs b/src/Tgstation.Server.Host/Components/Interop/CommContext.cs index d3f6b67caa..839086a3bb 100644 --- a/src/Tgstation.Server.Host/Components/Interop/CommContext.cs +++ b/src/Tgstation.Server.Host/Components/Interop/CommContext.cs @@ -121,6 +121,7 @@ namespace Tgstation.Server.Host.Components.Interop await (handler?.HandleInterop(command, cancellationToken) ?? Task.CompletedTask).ConfigureAwait(false); } + catch (OperationCanceledException) { } catch (Exception ex) { logger.LogDebug("Exception while trying to handle command json write: {0}", ex); diff --git a/src/Tgstation.Server.Host/Components/Watchdog/SessionController.cs b/src/Tgstation.Server.Host/Components/Watchdog/SessionController.cs index babd915f2c..daf5f459ac 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/SessionController.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/SessionController.cs @@ -429,6 +429,10 @@ namespace Tgstation.Server.Host.Components.Watchdog commandString, cancellationToken).ConfigureAwait(false); } + catch (OperationCanceledException) + { + throw; + } catch (Exception e) { logger.LogInformation("Send command exception:{0}{1}", Environment.NewLine, e.Message); diff --git a/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs b/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs index d2e0cdf6e4..e41e355764 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/Watchdog.cs @@ -623,6 +623,10 @@ namespace Tgstation.Server.Host.Components.Watchdog monitorState = new MonitorState(); //clean the slate and continue } } + catch (OperationCanceledException) + { + throw; + } catch (Exception e) { launchException = e; diff --git a/src/Tgstation.Server.Host/Controllers/InstanceController.cs b/src/Tgstation.Server.Host/Controllers/InstanceController.cs index 13d5adc19c..546030a35c 100644 --- a/src/Tgstation.Server.Host/Controllers/InstanceController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstanceController.cs @@ -332,7 +332,8 @@ namespace Tgstation.Server.Host.Controllers } catch (Exception e) { - Logger.LogError("Error changing instance online state! Exception: {0}", e); + if(!(e is OperationCanceledException)) + Logger.LogError("Error changing instance online state! Exception: {0}", e); originalModel.Online = originalOnline; originalModel.DreamDaemonSettings.AutoStart = oldAutoStart; if (originalModelPath != null) diff --git a/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs b/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs index 0013a65758..b5d8dcc59c 100644 --- a/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs +++ b/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs @@ -62,6 +62,10 @@ namespace Tgstation.Server.Host.Security principal = UserPrincipal.FindByIdentity(pc, user.SystemIdentifier); } + catch (OperationCanceledException) + { + throw; + } catch (Exception e) { logger.LogWarning("Error loading user for context type {0}! Exception: {1}", contextType, e);