From 7cb61925b02f20ebfc6379b25d615216ded9d128 Mon Sep 17 00:00:00 2001 From: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com> Date: Tue, 25 Jul 2023 14:12:00 +0200 Subject: [PATCH] Pass timeout in executioncontext instead of stepsrunner (#2714) * Pass timeout in executioncontext instead of stepsrunner * Fix linting --- src/Runner.Worker/ExecutionContext.cs | 13 ++++++++++--- .../Handlers/CompositeActionHandler.cs | 2 -- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Runner.Worker/ExecutionContext.cs b/src/Runner.Worker/ExecutionContext.cs index 69c47ab6d..dce933c8b 100644 --- a/src/Runner.Worker/ExecutionContext.cs +++ b/src/Runner.Worker/ExecutionContext.cs @@ -83,7 +83,7 @@ namespace GitHub.Runner.Worker // Initialize void InitializeJob(Pipelines.AgentJobRequestMessage message, CancellationToken token); void CancelToken(); - IExecutionContext CreateChild(Guid recordId, string displayName, string refName, string scopeName, string contextName, ActionRunStage stage, Dictionary intraActionState = null, int? recordOrder = null, IPagingLogger logger = null, bool isEmbedded = false, CancellationTokenSource cancellationTokenSource = null, Guid embeddedId = default(Guid), string siblingScopeName = null); + IExecutionContext CreateChild(Guid recordId, string displayName, string refName, string scopeName, string contextName, ActionRunStage stage, Dictionary intraActionState = null, int? recordOrder = null, IPagingLogger logger = null, bool isEmbedded = false, CancellationTokenSource cancellationTokenSource = null, Guid embeddedId = default(Guid), string siblingScopeName = null, TimeSpan? timeout = null); IExecutionContext CreateEmbeddedChild(string scopeName, string contextName, Guid embeddedId, ActionRunStage stage, Dictionary intraActionState = null, string siblingScopeName = null); // logging @@ -357,7 +357,8 @@ namespace GitHub.Runner.Worker bool isEmbedded = false, CancellationTokenSource cancellationTokenSource = null, Guid embeddedId = default(Guid), - string siblingScopeName = null) + string siblingScopeName = null, + TimeSpan? timeout = null) { Trace.Entering(); @@ -386,6 +387,12 @@ namespace GitHub.Runner.Worker child.ExpressionFunctions.Add(item); } child._cancellationTokenSource = cancellationTokenSource ?? new CancellationTokenSource(); + if (timeout != null) + { + // composite steps inherit the timeout from the parent, set by https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepstimeout-minutes + child.SetTimeout(timeout); + } + child.EchoOnActionCommand = EchoOnActionCommand; if (recordOrder != null) @@ -425,7 +432,7 @@ namespace GitHub.Runner.Worker Dictionary intraActionState = null, string siblingScopeName = null) { - return Root.CreateChild(_record.Id, _record.Name, _record.Id.ToString("N"), scopeName, contextName, stage, logger: _logger, isEmbedded: true, cancellationTokenSource: null, intraActionState: intraActionState, embeddedId: embeddedId, siblingScopeName: siblingScopeName); + return Root.CreateChild(_record.Id, _record.Name, _record.Id.ToString("N"), scopeName, contextName, stage, logger: _logger, isEmbedded: true, cancellationTokenSource: null, intraActionState: intraActionState, embeddedId: embeddedId, siblingScopeName: siblingScopeName, timeout: GetRemainingTimeout()); } public void Start(string currentOperation = null) diff --git a/src/Runner.Worker/Handlers/CompositeActionHandler.cs b/src/Runner.Worker/Handlers/CompositeActionHandler.cs index dbdd15d99..ee4854700 100644 --- a/src/Runner.Worker/Handlers/CompositeActionHandler.cs +++ b/src/Runner.Worker/Handlers/CompositeActionHandler.cs @@ -421,8 +421,6 @@ namespace GitHub.Runner.Worker.Handlers { Trace.Info($"Starting: {step.DisplayName}"); step.ExecutionContext.Debug($"Starting: {step.DisplayName}"); - // composite steps inherit the timeout from the parent, set by https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepstimeout-minutes - step.ExecutionContext.SetTimeout(step.ExecutionContext.Parent.GetRemainingTimeout()); await Common.Util.EncodingUtil.SetEncoding(HostContext, Trace, step.ExecutionContext.CancellationToken);