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}");