From fd9624658016d1eb2390a2e372f96806ebfe750d Mon Sep 17 00:00:00 2001 From: Nikola Jokic Date: Tue, 7 Mar 2023 14:09:10 +0100 Subject: [PATCH] Exit on deprication error (#2299) * terminate the runner on deprication message * added TaskAgentVersion exception to catch deprication * AccessDenied exception with inner exception InvalidTaskAgent * Access denied exception in program and in message listener * Fixed copy * remove trace message from message listener --- src/Runner.Listener/MessageListener.cs | 8 ++++++-- src/Runner.Listener/Program.cs | 11 +++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Runner.Listener/MessageListener.cs b/src/Runner.Listener/MessageListener.cs index 59eddfbb1..cb8edb607 100644 --- a/src/Runner.Listener/MessageListener.cs +++ b/src/Runner.Listener/MessageListener.cs @@ -182,7 +182,7 @@ namespace GitHub.Runner.Listener try { _getMessagesTokenSource?.Cancel(); - } + } catch (ObjectDisposedException) { Trace.Info("_getMessagesTokenSource is already disposed."); @@ -245,6 +245,10 @@ namespace GitHub.Runner.Listener _accessTokenRevoked = true; throw; } + catch (AccessDeniedException e) when (e.InnerException is InvalidTaskAgentVersionException) + { + throw; + } catch (Exception ex) { Trace.Error("Catch exception during get next message."); @@ -289,7 +293,7 @@ namespace GitHub.Runner.Listener await HostContext.Delay(_getNextMessageRetryInterval, token); } } - finally + finally { _getMessagesTokenSource.Dispose(); } diff --git a/src/Runner.Listener/Program.cs b/src/Runner.Listener/Program.cs index d4d5e43eb..b12eda66b 100644 --- a/src/Runner.Listener/Program.cs +++ b/src/Runner.Listener/Program.cs @@ -6,6 +6,7 @@ using System.IO; using System.Reflection; using System.Runtime.InteropServices; using System.Threading.Tasks; +using GitHub.DistributedTask.WebApi; namespace GitHub.Runner.Listener { @@ -58,7 +59,7 @@ namespace GitHub.Runner.Listener terminal.WriteLine("This runner version is built for Windows. Please install a correct build for your OS."); return Constants.Runner.ReturnCode.TerminatedError; } - #if ARM64 +#if ARM64 // A little hacky, but windows gives no way to differentiate between windows 10 and 11. // By default only 11 supports native x64 app emulation on arm, so we only want to support windows 11 // https://docs.microsoft.com/en-us/windows/arm/overview#build-windows-apps-that-run-on-arm @@ -69,7 +70,7 @@ namespace GitHub.Runner.Listener terminal.WriteLine("Win-arm64 runners require windows 11 or later. Please upgrade your operating system."); return Constants.Runner.ReturnCode.TerminatedError; } - #endif +#endif break; default: terminal.WriteLine($"Running the runner on this platform is not supported. The current platform is {RuntimeInformation.OSDescription} and it was built for {Constants.Runner.Platform.ToString()}."); @@ -137,6 +138,12 @@ namespace GitHub.Runner.Listener } } + catch (AccessDeniedException e) when (e.InnerException is InvalidTaskAgentVersionException) + { + terminal.WriteError($"An error occured: {e.Message}"); + trace.Error(e); + return Constants.Runner.ReturnCode.TerminatedError; + } catch (Exception e) { terminal.WriteError($"An error occurred: {e.Message}");